c - How do I get per-cpu stats (system, idle, nice, ...) like the "top" command does? -
On the linux, I want to know that the "C" API has to call to get per-CPU stats
I can read and read / proc / loadavg
from inside my app, but this system-wide load is top, not per-CPU information I want to tell different CPU or core.
As an example of such an application, when I run head
and press "1", then I can see 4 or 8 processors / core By way:
CPU: 4.5% us, 0.0% SE, 0.0% NI, 95.5% ID, 0.0% wa, 0.0% Hi, 0.0% C, 0.0% cp 1: 42.2 % Us, 6.2% SE, 0.5% NI, 51.2% ID, 0.0% W, 0.0% High, 0.0% C, 0.0% C CPU 2: 3.0% Us, 1.5% SE, 0.0% NI, 94.5% ID, 0.0 % W, 0.0% Hi, 1.0% C, 0.0% cpu 3: 7.0% us, 4.7% SE, 0.0% NI, 88.3% ID, 0.0% wa, 0.0% Hi, 0.0% C, 0.0% St. I tried to do strace top
, but it led the rat nest.
The file you want is / proc / stat
. (You can refer to fs / proc / stat.c
in the Linux kernel source.)
Comments
Post a Comment