DD2-monitor/funcs.c

41 lines
686 B
C

/*
* funcs.c
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "funcs.h"
extern int verbosity;
/* --------------------------------------------------------------- */
int get_loadavg(double *where)
{
FILE *fp;
double loads[3];
int foo;
if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
perror("read loadavg");
return -1;
}
foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2);
if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
memcpy(where, loads, 3 * sizeof(double));
fclose(fp);
return 0;
}
/* --------------------------------------------------------------- */