Is there any C API to calculate per CPU load?
/proc/loadavg gives the CPU average load for all available CPUs and
/proc/stat doesn't mention anything about active processes per CPU.
How can I obtain the load per CPU?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
There is no such thing as per-CPU load.
Load average is defined as the number of processes waiting on system resources. This isn't necessarily CPU. Also since a process might be waiting on CPU time, and isn't actively running on a CPU, you can't attribute it to any particular CPU since the process could end up running on any CPU (unless pinned).
However you can get utilization % per-CPU. Use
/proc/stat, and use the 4th field of each CPU to determine how idle that CPU is (See
man 5 proc and the
Basically read the value, sleep 1 second, read the value again, divide the difference by USER_HZ.