is it possible, in C++, to get the current RAM and CPU usage? Is there a platform-indepentent function call?
There is an open source library that gives these (and more system info stuff) across many platforms: SIGAR API I've used it in fairly large projects and it works fine (except for certain corner cases on OS X etc.) | |||
|
Sadly these things rely heavily on the underlying OS, so there are no platform-independent calls. (Maybe there are some wrapper frameworks, but I don't know of any.) On Linux you could have a look at the getrusage() function call, on Windows you can use GetProcessMemoryInfo() for RAM Usage. Have also a look at the other functions in the Process Status API of Windows. | |||||
|
No, there isn't, not in the standard. If you truly need this information, you will have to write platform-specific #ifdefs or link against a library that provides it. | |||
|
On Linux, this will use /proc/self/status . More work is required to turn this into a number. I find this useful as it is though, just to print the memory usage directly to the screen as a string.
| |||
|
Not directly. But you can use a library that abstracts the OS (such as ACE). | |||
|
There is no platform independent way to do this. Although for windows, you can get the CPU usage and performance metrics by using PDH.dll(Performance Data Helper) and its related APIs in your code. | |||
|
If that is still the case please check: http://sourceforge.net/projects/cpp-cpu-monitor/ It gives you an example how to get CPU and RAM usage of a Linux (tested on Debian and CentOS) and a quite simple instruction of how to install. Please feel free to ask if you have any questions regarding this small project. | |||
|