Waiting for CPU availablity
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.
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 ...
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)?
Next question: any simple way to start a program at a low priority (or must I write a wrapper program)?
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
Popular Topics
Advertisement