-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding small example on system load average
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |