Last active
November 4, 2020 17:08
-
-
Save AlexBaranowski/68a1549a3f2f29d5e26165bfae496f28 to your computer and use it in GitHub Desktop.
loadavg.c
This file contains hidden or 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
#include<sys/sysinfo.h> | |
#include<stdio.h> | |
// NOTE: FSHIFT might differ | |
#define FSHIFT 16 | |
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ | |
#define LOAD_INT(x) ((x) >> FSHIFT) | |
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) | |
int main(){ | |
struct sysinfo info; | |
sysinfo(&info); | |
printf("%lu.%02lu\n", LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0])); | |
printf("%lu.%02lu\n", LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1])); | |
printf("%lu.%02lu\n", LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment