Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, I need to find out when a CPU is in Idle mode. I sould retrieve the CPU activities for about 10 minutes and then calculate the usage. First, I couldn't measure the usage in percent and second, I'm not sure whether it's going to work on a multi core CPU or not.
Thanks
Posted
Updated 17-Sep-13 21:08pm
v3
Comments
Richard MacCutchan 18-Sep-13 3:18am    
If your program is running then it won't be idle.

You didn't mention the platform you are running on. On Windows I would try to use
C++
BOOL GetSystemTimes(
  LPFILETIME lpIdleTime,
  LPFILETIME lpKernelTime,
  LPFILETIME lpUserTime
);

and call that regularly, say every 10 seconds. The values you get from this call are cumulative since the start of the system. Hence you will have to do a little arithmetic to figure the CPU load averaged over the last 10 minutes.

Find some other useful information on Get CPU Usage with GetSystemTimes[^].
 
Share this answer
 
Comments
Mojtaba Setoodeh 19-Sep-13 3:49am    
i am using win 7 64b. tnx
nv3 19-Sep-13 4:11am    
Then this approach should work well for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900