-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrzy.c
70 lines (52 loc) · 1.76 KB
/
rzy.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/sysinfo.h>
#include <string.h>
#include <sys/utsname.h>
int main() {
/* Declares */
struct sysinfo si;
sysinfo (&si);
struct utsname un;
uname (&un);
int64_t total_ram, uptime, processes;
double megabyte = 1024 * 1024;
double ramMB, availableRAM, percentageUsed;
/* Colors */
char cr[10]= "\033[1;36m";
char cl[10] = "\033[0m";
/* Relevant user environment variables */
char *user = getenv("USER");
char *terminal = getenv("TERM");
char *shell = getenv("SHELL");
char *lang = getenv("LANG");
// Hostname
char hostname[_SC_HOST_NAME_MAX + 1];
gethostname(hostname, _SC_HOST_NAME_MAX + 1);
// Uptime
uptime = (float)si.uptime / 60;
// Total ram
total_ram = si.totalram *(unsigned long long)si.mem_unit / 1024;
// Read memory using free -m
FILE *fp; char path[1035];
fp = popen("free -m | awk '{print $3}'", "r");
fgets(path, sizeof(path), fp);
char mem[100];
fscanf(fp, "%s", mem);
// find ram in megabytes
ramMB = si.totalram/megabyte;
availableRAM = atof(mem);
percentageUsed = availableRAM/ramMB * 100;
/* Output */
printf("%s~ user -->%s %s@%s\n", cr, cl, user, hostname);
printf("%s~ release -->%s %s %s\n", cr, cl, un.release, un.machine);
printf("%s~ terminal -->%s %s\n", cr, cl, terminal);
printf("%s~ shell -->%s %s\n", cr, cl, shell);
printf("%s~ memory -->%s %s/%.0f - %.0f%%\n", cr, cl, mem, ramMB, percentageUsed);
printf("%s~ uptime -->%s %li minutes \n", cr, cl, uptime);
printf("%s~ locale -->%s %s\n", cr, cl, lang);
printf("%s~ procs -->%s %d\n", cr, cl, si.procs);
return 0;
}