Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 06-01-2009, 10:16 PM   #1
LQ Newbie
Registered: Jun 2009
Posts: 2

Rep: Reputation: 0
Lightbulb 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!

Old 06-01-2009, 11:35 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,047
Blog Entries: 11

Rep: Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907

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.
Old 06-02-2009, 12:04 AM   #3
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 06-02-2009 at 12:09 AM.
Old 06-02-2009, 02:07 AM   #4
LQ Newbie
Registered: Jun 2009
Posts: 2

Original Poster
Rep: Reputation: 0

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
Old 06-02-2009, 06:34 PM   #5
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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


hardware, monitor

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote performance monitor Thakowbbery Linux - Software 10 06-11-2009 06:55 AM
Best Performance Monitor Utilities? risheda Linux - Newbie 1 06-23-2006 08:39 PM
Performance monitor recommendations? Seventh Linux - Newbie 1 01-31-2006 05:02 PM
Hardware performance calutateo Linux - Hardware 2 01-27-2005 11:43 PM
Performance Monitor for linux vitsin Linux - Software 2 06-03-2004 07:28 AM

All times are GMT -5. The time now is 04:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration