How to calculate the CPU usage of a process by PID in Linux from C?
You need to parse out the data from /proc/<PID>/stat. These are the first few fields (from Documentation/filesystems/proc.txt in your kernel source): Table 1-3: Contents of the stat files (as of 2.6.22-rc3) …………………………………………………………………… Field Content pid process id tcomm filename of the executable state state (R is running, S is sleeping, D is sleeping in an … Read more