LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Hardware Performance Monitor via C++ (http://www.linuxquestions.org/questions/programming-9/hardware-performance-monitor-via-c-730003/)

svshivshan 06-01-2009 10:16 PM

Hardware Performance Monitor via C++
 
Hi,

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!

-svshivshan

Tinkster 06-01-2009 11:35 PM

Hi,

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.

Code:

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


Cheers,
Tink


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-02-2009 12:04 AM

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

http://linuxgazette.net/issue46/fink.html
http://www.linuxjournal.com/article/2396

'Hope that helps .. PSM

svshivshan 06-02-2009 02: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 06: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 02:04 AM.