cpu activity

David J. C. Beach beach at verinet.com
Thu Nov 20 16:27:15 EST 2003


On Thu, 2003-11-20 at 16:07, Chris Devers wrote:
> Surely this is one of the simpler ways to do it:
> 
>     $ uptime
>     16:04  up 7 days, 19:45, 8 users, load averages: 4.74 4.25 3.55
> 
>     $ uptime | awk '{print $10}'
>     4.78
> 
> Wouldn't anything from /proc just have that same value?

uptime or /proc/update works nice if you want a longer-running load
average of cpu usage.  At other times, it's a lot nicer to get a
measurement of "instantaeous" CPU usage (as a percentage).  You can do
this by peeking at /proc/stat.

The first line looks like this:

cpu <user> <nice> <system> <idle>

where the last 4 items are integer counts of a number of jiffies. 
According to the man page, a jiffie is 1/100th of a second.

If you compare the values of reading /proc/stat twice in a row, which a
small interval of time in between (it can be less than 1 second, but
should probably be a least 1/10th of a second), you can get a crude idea
for the instaneanous use on your CPU.

Dave

-- 
David J. C. Beach
<beach at verinet.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.blu.org/pipermail/discuss/attachments/20031120/8c5afd7d/attachment.sig>


More information about the Discuss mailing list