Nick Rout wrote:

> Anyway its ps is a shell hack that obtains stats from the proc tree and
> dosen't show cpu usage.  Ho hum. Can anyone tell me whereabouts in /proc
> you find cpu usage?

Its messy.  If there is an easy way I'd love to know because I've had to 
implement it the hard way myself for the LCD project.

For an individual process you need to look at /proc/xx/stat where xx is 
the pid.  The user mode and system mode "jiffies of CPU time" are 
fields... 14 and 15 respectively, I think.  Add these numbers together 
and you get the total CPU time the process has used since it was started. 
 You need to take two timestamped readings then calculate the CPU % from 
there.  This is how 'top' works.  BTW a "jiffie" in the Linux kernel is 
about 1/100th of a second.

For the system as a whole, see /proc/uptime.  The two numbers here are 
system uptime and system idle time respectively.  The difference between 
these is the system busy time, in seconds, since the last reboot.  Again, 
you have to take two timestamped readings.  System load from this method 
is fooled by kapm-idled if your kernel has the APM idle loop enabled.  So 
you need to look in /proc/3/stat, and if its kapm-idled you subtract its 
CPU usage from your system figure (grumble).

It'd be pretty simple to write a program to get this info for you (since 
I've already done it for another project I can just cut & paste the 
code).  However you'd need to be able to compile it... in which case you 
might be better off just getting the procps suite, which contains 'top'.

Cheers,

- Dave

http://www.digistar.com/~dmann/


Reply via email to