Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) 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:

#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);

In reply to Re: Checking that local Windows machine is idle by saucepan
in thread Checking that local Windows machine is idle by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-08-21 10:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (134 votes), past polls