2005-11-14 16:48:12 +01:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2010-09-14 23:28:34 +02:00
|
|
|
#include <minix/paths.h>
|
2005-11-14 16:48:12 +01:00
|
|
|
#include <stdlib.h>
|
2010-09-14 23:28:34 +02:00
|
|
|
#include <stdio.h>
|
2005-11-14 16:48:12 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <lib.h>
|
|
|
|
|
|
|
|
/* Retrieve system load average information. */
|
|
|
|
int getloadavg(double *loadavg, int nelem)
|
|
|
|
{
|
2010-09-14 23:28:34 +02:00
|
|
|
FILE *fp;
|
|
|
|
int i;
|
2008-12-11 15:37:18 +01:00
|
|
|
|
2005-11-14 16:48:12 +01:00
|
|
|
if(nelem < 1) {
|
|
|
|
errno = ENOSPC;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-14 23:28:34 +02:00
|
|
|
if((fp = fopen(_PATH_PROC "/loadavg", "r")) == NULL)
|
2005-11-14 16:48:12 +01:00
|
|
|
return -1;
|
|
|
|
|
2010-09-14 23:28:34 +02:00
|
|
|
for(i = 0; i < nelem; i++)
|
|
|
|
if(fscanf(fp, "%lf", &loadavg[i]) != 1)
|
|
|
|
break;
|
2005-11-14 16:48:12 +01:00
|
|
|
|
2010-09-14 23:28:34 +02:00
|
|
|
fclose(fp);
|
2005-11-14 16:48:12 +01:00
|
|
|
|
2010-09-14 23:28:34 +02:00
|
|
|
if (i == 0) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
2005-11-14 16:48:12 +01:00
|
|
|
}
|
|
|
|
|
2010-09-14 23:28:34 +02:00
|
|
|
return i;
|
2005-11-14 16:48:12 +01:00
|
|
|
}
|