|Syntactic Confectionery Delight|
Re: Checking that local Windows machine is idleby saucepan (Scribe)
|on Feb 04, 2001 at 07:14 UTC||Need Help??|
This depends on what you mean by "idle." The screensaver will fire up when there have been no keyboard or mouse events for N minutes, even if the CPU is pegged at 100% at the time (by the distributed.net client, say).
If the screensaver's idea of idle matches your requirements, you could do a lot worse than to take Corion's advice and just install your script as the screensaver.
Alternately, you could write a wrapper script that uses Win32::Process to launch your real script with IDLE_PRIORITY_CLASS; then, you know the CPU is idle because when it isn't, your code isn't running. :)
If that's too kludgey, you can wade into Win32::API and figure out how to call SetPriorityClass (or maybe SetThreadPriority) from perl (both are found in kernel32.dll.. the docs I've got suggest that the HANDLE arg isn't optional, so you'll need to find a way to get hold of your own proc/thread handle to use these calls.)
If you are really feeling adventurous, you can query for a variety of performance counters using Win32::PerfLib (assuming WinNT or Win2k, mind you).
update: It would be cool if POSIX::nice would work -- it being portable and all -- but it isn't implemented on ActivePerl 623 on my Win98 box here at home. Anyone know if it works on NT or Win2k?
update: If you decide to use Win32::API, here's the rest of the info you'll need: