¥
Size: a a a
¥
#
#
¥
¥
¥
¥
¥
¥
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/sysctl.h>
#include <stdlib.h>
#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
int
getloadavg(double loadavg[], int nelem)
{
struct loadavg loadinfo;
int i, mib[2];
size_t size;
mib[0] = CTL_VM;
mib[1] = VM_LOADAVG;
size = sizeof(loadinfo);
if (sysctl(mib, 2, &loadinfo, &size, NULL, 0) == -1)
return (-1);
nelem = MINIMUM(nelem, sizeof(loadinfo.ldavg) / sizeof(fixpt_t));
for (i = 0; i < nelem; i++)
loadavg[i] = (double) loadinfo.ldavg[i] / loadinfo.fscale;
return (nelem);
}
N
¥
N
N
¥
N
¥
¥