Skip to content

Commit

Permalink
Adding small example on system load average
Browse files Browse the repository at this point in the history
  • Loading branch information
k0ffee committed Dec 19, 2017
1 parent 3376917 commit 6a5bbd9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions loadavg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>

int main() {
double loadavg;
static const double maxload = 150;

/*
* 1-minute sample:
* double loadavg;
* if (getloadavg(&loadavg, 1) == 1)
* if (loadavg < maxload) ...
* 5-minute sample (using second element returned by getloadavg):
* double loadavg[2];
* if (getloadavg(loadavg, 2) == 2)
* if (loadavg[1] < maxload) ...
*/

if (getloadavg(&loadavg, 1) == 1) {

if (loadavg < maxload) {
printf("%f < %f\n", loadavg, maxload);
} else if (loadavg >= maxload) {
printf("%f >= %f\n", loadavg, maxload);
}
}

return 0;
}

0 comments on commit 6a5bbd9

Please sign in to comment.