-   Programming (
-   -   Hardware Performance Monitor via C++ (

svshivshan 06-01-2009 09:16 PM

Hardware Performance Monitor via C++

I want to find a way in C++ to get the performance of system hardware like cpu load, ram usage (for all processes at that time), screen display resolution and power consumption of the system.

For windows, there are functions in windows.h like GetSystemPowerStatus(), GlobalMemoryStatusEx() etc that can be used in c++ program to get the system hardware states.

How can i possibly do this in c++ for linux systems?

Thank you in advance!


Tinkster 06-01-2009 10:35 PM


welcome to LQ!

I'm afraid that this is *not* exposed via any API or system calls.

Looking at the source for ps (from procps) suggests that using
the /proc/*/stat file per process is the thing to do to gather
most of that info.


tar xvf procps-3.2.7.tar.gz
cd procps-3.2.7
less ./proc/readproc.c


P.S.: I'm moving this to our programming forum, in the hope there's
more clued-up people watching there who may be able to prove me wrong.

paulsm4 06-01-2009 11:04 PM

Tinkster's correct (so, like what *else* is new? ;-)) - "/proc" is the way to go. Here are a couple of good links:

'Hope that helps .. PSM

svshivshan 06-02-2009 01:07 AM

Thank you very much both of you. I am now less confused.

Since I installed ubuntu only a couple of days back and am totally new to it, I am unable to grasp how to bring these under an executable program.

I understand that the system information is contained in proc. How can i embed this info into a C++ program. For example: a fn call to a windows api function would give me the system information. How can this be done for linux? How can i automatically execute commands in linux and where can i store the information returned?

I am sorry if I am silly. Your help would be of great value to me. Many thanks!

- svshivshan

paulsm4 06-02-2009 05:34 PM

Hi -

It's surprisingly simple: you simple open the special "/proc/XXX" directory as though it were a disk file ... and read it.

For example, "fopen ()", then "fgets()".

It's as simple as that!

Your .. PSM

All times are GMT -5. The time now is 03:17 AM.