initial commit
This commit is contained in:
18
sb-memory.c
Normal file
18
sb-memory.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
FILE *fp = fopen("/proc/meminfo", "r");
|
||||
if (!fp)
|
||||
return 1;
|
||||
|
||||
long long total = 0, available = 0;
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), fp) && (!total || !available)) {
|
||||
sscanf(line, "MemTotal: %lld kB", &total);
|
||||
sscanf(line, "MemAvailable: %lld kB", &available);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
printf("Mem: %.0f%%\n", (double)(total - available) / total * 100);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user