Created
October 3, 2018 02:13
-
-
Save john302/37c920a06927add0a55b8ae51a05fa7d to your computer and use it in GitHub Desktop.
Print Linux system information in C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct utsname uname_pointer; | |
/* Conversion constants. */ | |
const long minute = 60; | |
const long hour = minute * 60; | |
const long day = hour * 24; | |
const double megabyte = 1024 * 1024; | |
/* Obtain system statistics. */ | |
struct sysinfo si; | |
sysinfo (&si); | |
/* Summarize interesting values. */ | |
printf ("System uptime : %ld days, %ld:%02ld:%02ld\n", | |
si.uptime / day, (si.uptime % day) / hour, | |
(si.uptime % hour) / minute, si.uptime % minute); | |
printf ("Total RAM : %5.1f MB\n", si.totalram / megabyte); | |
printf ("Free RAM : %5.1f MB\n", si.freeram / megabyte); | |
printf ("Number of running processes : %d\n", si.procs); | |
uname(&uname_pointer); | |
printf ("System name : %s \n" \ | |
"Nodename : %s \n" \ | |
"Release : %s \n" \ | |
"Version : %s \n" \ | |
"Machine : %s \n", | |
uname_pointer.sysname, | |
uname_pointer.nodename, | |
uname_pointer.release, | |
uname_pointer.version, | |
uname_pointer.machine | |
); | |
return EXIT_SUCCESS; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment