2018-12-06 02:00:11 +11:00
|
|
|
/*
|
|
|
|
* funcs.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-12-14 05:39:06 +11:00
|
|
|
#include <unistd.h>
|
2018-12-06 02:00:11 +11:00
|
|
|
#include <stdlib.h>
|
2018-12-11 10:33:15 +11:00
|
|
|
#include <string.h>
|
2018-12-14 05:39:06 +11:00
|
|
|
#include <time.h>
|
2018-12-06 03:58:55 +11:00
|
|
|
#include <sys/time.h>
|
2018-12-06 02:00:11 +11:00
|
|
|
|
|
|
|
#include "funcs.h"
|
|
|
|
|
2018-12-06 02:04:09 +11:00
|
|
|
extern int verbosity;
|
|
|
|
|
2018-12-06 03:58:55 +11:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------- */
|
|
|
|
|
2018-12-08 23:02:24 +11:00
|
|
|
int get_loadavg(double *where)
|
2018-12-06 21:14:29 +11:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2018-12-08 23:02:24 +11:00
|
|
|
double loads[3];
|
|
|
|
int foo;
|
2018-12-06 21:14:29 +11:00
|
|
|
|
|
|
|
if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
|
|
|
|
perror("read loadavg");
|
2018-12-08 23:02:24 +11:00
|
|
|
return -1;
|
2018-12-06 21:14:29 +11:00
|
|
|
}
|
|
|
|
|
2018-12-08 23:02:24 +11:00
|
|
|
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));
|
|
|
|
|
2018-12-06 21:14:29 +11:00
|
|
|
fclose(fp);
|
|
|
|
|
2018-12-08 23:02:24 +11:00
|
|
|
return 0;
|
2018-12-06 21:14:29 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------- */
|