Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cpu activity

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.


David J. C. Beach
<beach at>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <>

BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!

Boston Linux & Unix /