I want to get the overall total CPU usage for an application in C, the total CPU usage like we get in the TaskManager…
I want to know … for windows and linux :: current Total CPU utilization by all processes ….. as we see in the task manager.
I want to get the overall total CPU usage for an application in C,
Share
This is platform-specific:
GetProcessTimes()function.clock().These can be used to measure the amount of CPU time taken between two time intervals.
EDIT :
To get the CPU consumption (as a percentage), you will need to divide the total CPU time by the # of logical cores that the OS sees, and then divided by the total wall-clock time:
Getting the # of logical cores is also platform-specific:
GetSystemInfo()sysconf(_SC_NPROCESSORS_ONLN)