Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Checking that local Windows machine is idle

by saucepan (Scribe)
on Feb 04, 2001 at 07:14 UTC ( #56271=note: print w/ replies, xml ) Need Help??


in reply to Checking that local Windows machine is idle

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:

#define IDLE_PRIORITY_CLASS 0x00000040 HANDLE GetCurrentProcess(VOID); BOOL SetPriorityClass(HANDLE hProcess, DWORD dwPriorityClass); #define THREAD_PRIORITY_LOWEST -2 HANDLE GetCurrentThread(VOID); BOOL SetThreadPriority(HANDLE hThread, int nPriority);


Comment on Re: Checking that local Windows machine is idle
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://56271]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-12-28 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (178 votes), past polls