blob: 9e880d2a4fa31a71d4acc6f3ad4046c8ecd4a055 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include "../include/cfetch.h"
void get_memory(system_info_t *info) {
FILE *file = fopen("/proc/meminfo", "r");
if (!file) {
perror("Error fopen meminfo");
return;
}
char line[256];
long total = 0;
long available = 0;
// read per line
while (fgets(line, sizeof(line), file)) {
if (sscanf(line, "MemTotal: %ld kB", &total) == 1) continue;
if (sscanf(line, "MemAvailable: %ld kB", &available) == 1) continue;
}
fclose(file);
printf("Memory: %.2f GB / %.2f GB\n", (total - available) / (1024.0 * 1024.0), total / (1024.0 * 1024.0));
return;
}
|