Re: [Queue-developers] load average
Brought to you by:
wkrebs
|
From: Tim C. <tim...@in...> - 2001-01-05 11:15:32
|
On Sat, Jan 05, 2002 at 05:09:20PM +0800, xieshuang wrote:
> Hi
>
> Can anybody teach me the details about how to calculate load average on unix system?
I'm not sure there's a uniform way to do it. You might want to look at
the source code for a free version of top, or something like that?
Should give you methods for lots of operating systems.
For Linux, it's trivial:
float one_minute, five_minute, fifteen_minute;
FILE *fh;
fh = fopen("/proc/loadavg", "r");
if (fh != NULL) {
if (fscanf(fh, "%f %f %f", &one_minute, &five_minute, &fifteen_minute)
== 3) {
printf("Five minute load average is: %f\n", five_minute);
}
fclose(fh);
}
There are two other items in /proc/loadavg; the first is
number_running_processes/total_processes, and the second is the last
PID.
Tim.
--
Tim Cutts PhD Tel: +44 1223 454918
Incyte Genomics
Botanic House, 100 Hills Road, Cambridge, CB2 1FF, UK
|