Getting System Information from Linux
November 10, 2008 on 3:37 pm | In Programming | By QBasicer |Most of the information I gather for my Linux version of my uptime program comes from procfs.
/proc/sys/kernel/hostname
Provides me the one word hostname of this kernel. I’m planning on switching this and /proc/version to a uname() syscall (see man 3 uname) to provide better compatibility on systems without /proc.
/proc/uptime
Provides me the raw number of seconds (including factional) since the computer booted, as well as the total number of seconds this computer has been idle (the second bit I discard)
/proc/loadavg
Provides me with the three load averages
/proc/version
Provides me with a long kernel version, which is different than the one supplied by uname -a.
/proc/meminfo
I get all of my memory information from here, but I don’t use all of the information available to me. Most of it is pretty useless, but I do get:
- Total Memory
- Buffered Memory
- Cached Memory
- Free Memory
- Total Swap
- Free Swap
I get ‘memory used’ from the formula: “int memused = memtotal - cached - buffers - memfree;”
2 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with Pool theme design by Borja Fernandez. I rewrote the CSS because I'm cool like that.
Entries and comments feeds.
Valid XHTML and CSS. ^Top^

Isn’t procfs depricated? I thought we were supposed to do everything through the ultra-complicated sysfs…
Comment by BioHazard — November 20, 2008 #
Not really, but there’s a lot of sysctl calls you can use. I currently use sysctl on OSX to get information, and I’ll probably try to port all that over to Linux and FreeBSD because it seems to be the best solution.
Comment by QBasicer — November 20, 2008 #