Get system info from C program?
Posted
by
Hamid
on Programmers
See other posts from Programmers
or by Hamid
Published on 2012-09-05T18:44:16Z
Indexed on
2012/09/05
21:49 UTC
Read the original article
Hit count: 253
I'm writing a little program in C that I want to use to output some system stats to my HD44780 16x2 character display. The system I'll be working with is a Debian ARM system and, although irrelevant, the display is on the GPIO header.(The system is a Raspberry Pi).
As an initial (somewhat unambitious) attempt, I'd like to start with something simple like RAM and CPU usage (I'm new to C).
I understand that if I make external command calls I need to fork() and execve() (or some equiv that will let me return the results), what I would like to know is how I go about getting the information I want in a nice clean format that I can use.
Surely I will not have to call (for e.g);
free -h
And then use awk or similar to chop out the piece I want? There must be a cleaner way?
The question should be seen as more of a generic, what is best practice for getting info about the system in C (the RAM/CPU usage are just an initial example).
© Programmers or respective owner