The cleanest way is to use procfs (see Dietrich's answer).
However, for more detailed information about the equipment (RAM, number of processors, speed, model numbers, other devices), you can extract tons of information from dmesg:
dmesg | grep Memory
You can use C stdlib popen () to read from dmesg, if you have privileges, and parse all kinds of information. I used this for a monitoring system such as Spong to extract as much information as possible about the node. You can even track it in real time for feedback with your hardware / device commands (dmesg | tail -f).
Remember that dmesg is not always available, depending on privileges.
source share