[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getloadavg not universally available
From: |
Phil D'Amore |
Subject: |
Re: getloadavg not universally available |
Date: |
Wed, 19 Feb 2003 08:54:00 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003 |
If anyone is interested, I had to write the attached for something a
while back. It emulates the Linux/Solaris interface to getloadavg() on
a AIX box. I have tested this against various 4.x incarnations of AIX
but it has never been tested against 5.x. Actually I'm not too fluent
in AIX 5 but I'd be surprised if it does not contain this function already.
Later,
--
Phil D'Amore "Y'know, there was a time when
Senior System Administrator corporate responsibility meant
Red Hat, Inc having the decency to jump out of
Office: 919.754.3700 x44395 a window when you got caught"
Cell: 919.641.3669 -- Non-Sequitur, 09/30/2002
#include <stdio.h>
#include <nlist.h>
#include <errno.h>
#include <fcntl.h>
#define LOADAVG_1MIN 0
#define LOADAVG_5MIN 1
#define LOADAVG_15MIN 2
main(void)
{
double loadavg[3];
getloadavg(loadavg, 3);
printf("Load average: %.2f, %.2f, %.2f\n", loadavg[0], loadavg[1],
loadavg[2]);
}
getloadavg(double loadavg[], int nelem)
{
struct nlist nl;
int kmem, i;
long avenrun[3];
nl.n_name = "avenrun";
nl.n_value = 0;
if(knlist(&nl, 1, sizeof(nl)))
{
return -1;
}
if((kmem = open("/dev/kmem", 0, 0)) <= 0)
{
return -1;
}
if(pread(kmem, avenrun, sizeof(avenrun), nl.n_value) < sizeof(avenrun))
{
return -1;
}
for(i=0;i<nelem;i++)
{
loadavg[i] = (double) avenrun[i] / 65535;
}
return i;
}