diff options
| author | Inqiyad Sabr <sabr@ariamath.xyz> | 2025-10-22 23:29:12 +0600 |
|---|---|---|
| committer | Inqiyad Sabr <sabr@ariamath.xyz> | 2025-10-22 23:29:12 +0600 |
| commit | 2f79dd96972201b147d9c1a5ec94cc0f543959b9 (patch) | |
| tree | afad4083f8bb0318c95886a6a7fc4fbcaaf8d9c4 /mem.c | |
| parent | 9689404d6ecbda6ff6fe5a9f8a078d3409d19f3a (diff) | |
Added memory status module
Diffstat (limited to 'mem.c')
| -rw-r--r-- | mem.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +#include <stdio.h> +#include "block.h" +#define ICON_MEM " " +#define FG "#222222" +#define BG "#95b18b99" +#define mem_val(n)\ + for(n = 0; (c = fgetc(meminfo)) != '\n';)\ + if (c >= '0' && c <= '9')\ + n = 10 * n + (c - '0') +#define jmpl(n) fseek(meminfo,29*(n-1),0) +FILE *meminfo; +int mem_delay = 3; +char mem_str[15]; +void mem(void) { + if (mem_delay++ < 3) goto show_stat; + else mem_delay = 0; + if (!meminfo) meminfo = fopen("/proc/meminfo","r"); + int c, mem; + int total, free, buffers, + cached, shared, reclaim; + jmpl(1); mem_val(total); + jmpl(2); mem_val(free); + jmpl(4); mem_val(buffers); + jmpl(5); mem_val(cached); + jmpl(23); mem_val(shared); + jmpl(26); mem_val(reclaim); + mem = total + reclaim - (free+buffers+cached+shared); + mem /= 1024; + snprintf(mem_str,15,ICON_MEM"%5d MiB",mem); +show_stat: + block(mem_str,FG,BG,BG); +} |