LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 0
Lightbulb 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
 
Old 06-01-2009, 10:35 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
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.
 
Old 06-01-2009, 11:04 PM   #3
paulsm4
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:

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

'Hope that helps .. PSM

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

Original Poster
Rep: Reputation: 0
Question

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, 05:34 PM   #5
paulsm4
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
 
  


Reply

Tags
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 05:55 AM
Best Performance Monitor Utilities? risheda Linux - Newbie 1 06-23-2006 07:39 PM
Performance monitor recommendations? Seventh Linux - Newbie 1 01-31-2006 04:02 PM
Hardware performance calutateo Linux - Hardware 2 01-27-2005 10:43 PM
Performance Monitor for linux vitsin Linux - Software 2 06-03-2004 06:28 AM


All times are GMT -5. The time now is 01:53 AM.

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