Linux, you can use SysInfo to get information about your system.
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <linux/unistd.h >/* for _SYSCALLX macros/related stuff */#include <linux/kernel.h>/* for struct sysinfo */ _SYSCALL1 (int, sysinfo, struct sysinfo *, info); /* note:if copy directly from the Nroff source, remember to * REMOVE the extra backslashes in the printf state ment. */int main (void) {struct sysinfo s_info; int error; Error = SysInfo (&s_info); printf ("Code error =%d\n", error); printf ("Uptime =%lds\nload:1 min%lu/5 min%lu/15 min%lu\n" "Ram:total%lu/free%lu/shared%l u\n "" Memory in buffers =%lu\nswap:total%lu/free%lu\n "" Number of processes =%d\n ", S_info.uptime, S_info.loads[0], s_info.loads[1], s_info.loads[2], S_ Info.totalraM, S_info.freeram, S_info.sharedram, S_info.bufferram, S_info.totalswap, S_info.freeswap , S_info.procs); Exit (exit_success); }
Code Error = 0
Uptime = 47428s
Load:1 min 192/5 min 2272/15 min 2976
Ram:total 1027239936/free 249516032/shared 0
Memory in buffers = 0
Swap:total 2147479552/free 2092707840
Number of processes = 391
Linux SysInfo Obtaining system-related information