rovf has asked for the wisdom of the Perl Monks concerning the following question:

I would like to lower the priority of my Perl process on Windows. In Re: Changing Windows Process Priority I found a solution to a very similar problem. From http://sourceware.org/pthreads-win32/manual/PortabilityIssues.html I conclude that I need to set the priority to BELOW_NORMAL_PRIORITY_CLASS, so my solution looks like this:

use Win32::Process; my $currentProcess; if (Win32::Process::Open($currentProcess, Win32::Process::GetCurrentPr +ocessID(), 0)) { $currentProcess->SetPriorityClass(BELOW_NORMAL_PRIORITY_CLASS); } else { warn "Can not find myself ($^E)\n"; }
This doesn't compile, however, because BELOW_NORMAL_PRIORITY_CLASS is not defined in Win32::Process (and indeed, the perldocs don't mention this constant).

How can I do this properly?
-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: How to lower my own priority on Windows?
by Anonymous Monk on Oct 05, 2009 at 12:04 UTC
    Win32::Process says it is exported by request only, So
    use Win32::Process qw[ BELOW_NORMAL_PRIORITY_CLASS ];
    or
    Win32::Process::BELOW_NORMAL_PRIORITY_CLASS();
      Win32::Process says it is exported by request only
      Mine doesn't. From the perldocs:

      The following additional constants are exported by request only: STILL_ACTIVE
      and indeed, if I try your suggestion, I get
      "BELOW_NORMAL_PRIORITY_CLASS" is not exported by the Win32::Process mo +dule
      I'm using ActiveState Perl 5.8.8. Maybe this constant was introduce only with the Win32::Process version which came with Perl 5.10?

      -- 
      Ronald Fischer <ynnor@mm.st>
        I'm using ActiveState Perl 5.8.8. Maybe this constant was introduce only with the Win32::Process version which came with Perl 5.10?

        I don't know, I just install from cpan, though the latest is also available from ppm

Re: How to lower my own priority on Windows?
by Anonymous Monk on Oct 05, 2009 at 13:20 UTC
    BELOW_NORMAL_PRIORITY_CLASS and its sister ABOVE_NORMAL_PRIORITY_CLASS were introduced at Windows NT 5.0, sorry, Windows 2000. A lot of Win32 code is built for the more generice NT 3.5.

    From the Win32::Process Changes file (on CPAN):
    0.13 Fri Jun 13 2008 ... - Add ABOVE_NORMAL_PRIORITY_CLASS and BELOW_NORMAL_PRIORITY_CLASS constants (not exported by default). ...
    So it looks like you need a later version for these constants. I have not tried this, but it is possible you could declare your own:
    BELOW_NORMAL_PRIORITY_CLASS 0x00004000 ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
Re: How to lower my own priority on Windows?
by lostjimmy (Chaplain) on Oct 05, 2009 at 13:23 UTC
    BELOW_NORMAL_PRIORITY_CLASS is defined in winbase.h, so you should just be able to define your own constant. It is defined as follows: #define BELOW_NORMAL_PRIORITY_CLASS    0x00004000