Waiting for CPU availablity

Started by
6 comments, last by Spoonbender 18 years, 10 months ago
Anyone know a quick and dirty way of checking if the CPU is sitting idle (the Idle process has X% of the CPU)? What I am trying to achieve is a way to prevent (or delay) scheduled tasks from running while the CPU is busy doing other things. I was thinking of a wrapper program that would wait until the CPU was available before running another command. OS is Windows. Cross-platform and multi-CPU support are not necessary. Thanks chaps.
Advertisement
Maybe just start your thread and set the priority to low (or idle)...

Regards
visit my website at www.kalmiya.com
You can use windows API with the performance counter

Here's a quick demo /w source code

http://www.codeproject.com/system/cpuusage.asp



But doing so is giving yourself a bunch of trouble ... I must admit that using a low-priority thread is, I beleive, the best solution ...
OK, thanks.

Next question: any simple way to start a program at a low priority (or must I write a wrapper program)?
SetPriorityClass
'start /low blah.exe' from the command line.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Quote:Original post by Martee
'start /low blah.exe' from the command line.

Thanks [smile]
Quote:Anyone know a quick and dirty way of checking if the CPU is sitting idle (the Idle process has X% of the CPU)?

Err, thats technically impossible. To check what the CPU is doing, you need, that's right... the CPU, which means it won't be idle. ;)

But yeah, as other people have said, run at low priority, and you get the effect you need.

Note, this varies from OS to OS. On Windows, low priority processes will only be run when no higher-priority processes are available.

On Linux, a low priority process would still get occasional timeslices, even if a higher priority process is available. Just not as often as the high priority one.

This topic is closed to new replies.

Advertisement