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!
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.
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.
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!
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:18 PM.|