Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current CPU and RAM usage in C++?

Tags:

c++

ram

cpu-usage

is it possible, in C++, to get the current RAM and CPU usage? Is there a platform-indepentent function call?

like image 431
tunnuz Avatar asked Jan 26 '09 13:01

tunnuz


People also ask

How do I check my current usage of CPU and RAM?

Press Ctrl + Shift + Esc to launch Task Manager. Or, right-click the Taskbar and select Task Manager. Select the Performance tab and click Memory in the left panel. The Memory window lets you see your current RAM usage, check RAM speed, and view other memory hardware specifications.

How do I check my CPU usage?

Using Task Manager to Check CPU UsageStart by pressing CTRL + Shift + Esc on your keyboard. In the following window, click Task Manager. While in Task Manager, click the Performance tab. Here in the Performance tab, you can see how much of the CPU the computer is currently using.


1 Answers

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.

like image 71
Kosi2801 Avatar answered Sep 23 '22 15:09

Kosi2801