mirror of
https://github.com/vattam/BSDGames.git
synced 2025-12-20 19:04:49 +00:00
Initial revision
git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
26
lib/getloadavg.c
Normal file
26
lib/getloadavg.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* getloadavg.c - bsd-games implementation of getloadavg */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
getloadavg(double loadavg[], int nelem)
|
||||
{
|
||||
double load_averages[3];
|
||||
FILE *fp;
|
||||
int count;
|
||||
int i;
|
||||
int nc;
|
||||
fp = fopen("/proc/loadavg", "r");
|
||||
if (fp == NULL)
|
||||
return -1;
|
||||
count = fscanf(fp, "%lf%lf%lf", &(load_averages[0]), &(load_averages[1]),
|
||||
&(load_averages[2]));
|
||||
fclose(fp);
|
||||
if ((count == EOF) || (count == 0))
|
||||
return -1;
|
||||
nc = ((nelem < count) ? nelem : count);
|
||||
for (i = 0; i < nc; i++)
|
||||
loadavg[i] = load_averages[i];
|
||||
return nc;
|
||||
}
|
||||
Reference in New Issue
Block a user