#include #include "memory.h" int memory(void) { FILE *file = fopen("/proc/meminfo", "r"); if (!file) { fclose(file); perror("fopen"); return 1; } 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 0; }