Hello,

I would like to write a simple cpu monitoring program and need to get
the current cpu stats.

It looks like I could get the info from /proc/stat, but I'm having
trouble makeing sense of it.  I thought I had figured it out, but the
numbers I get don't change with system load.  As an example, here's
the first line of my /proc/stat file:

        cpu  278485 11148 67657 4231952

According to the proc(5) manpage, these numbers are "The number of
jiffies (1/100ths of a second) that the system spent in user mode,
user mode with low priority (nice), system mode, and the idle task,
respectively."  I thought that by adding fields 2-5, multiplying by
100 and dividing field 5 by the result, for example, would give me the
current percentage of idle cpu time.  It comes pretty close to top's
statistic, but doesn't match exactly and doesn't go down when I load
the system.

Then I thought maybe I shouldn't include the second field as it seems
it would be a subset of field 1, but that didn't help.

Here's the command I ran to test things:

gawk '$1=="cpu" {total=$2+$3+$4+$5; print("Idle: "$5*100/total)}'
/proc/stat

I'm running Seawolf with kernel 2.4.9-ac14 on a single-processor
Intel box.

Anyone know of any good sources of info on this?  (I don't know C, so
the source would probably not help me much. :)

Thanks,
Ben Logan
-- 
When Linux won't install on some hardware configuration, it means you
you need to switch to Windoze; but when a M$ product won't install, it
means you need to buy a new computer.



_______________________________________________
Seawolf-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/seawolf-list

Reply via email to