in reply to how to change process & thread priority on Win32 ?

Hi rbutcher,

You should check out the SetPriorityClass method of Win32::Process.
However, perhaps the script you are running is not as efficient as it could be, in which case it would be better to benchmark your script and find out what is going on.

Hope this helps.

Martin

Replies are listed 'Best First'.
Re^2: how to change process & thread priority on Win32 ?
by rbutcher (Beadle) on Nov 29, 2005 at 13:24 UTC
    Thanks Martin, I can set the process priority OK with $obj-> SetPriorityClass($priority) where $priority = 32, 16384 etc. But I can't make it set Thread Priority to 1, 0, -1 etc. The doco. says THREAD_PRIORITY_HIGHEST, _IDLE, _LOWEST etc are "exported by default" - how do I use them ?
        I've discovered that the exported values for the various THREAD_PRIORITY_ disagree with the values my C acquaintance gave me. The values exported by Win32::Process are :
        THREAD_PRIORITY_HIGHEST -1 THREAD_PRIORITY_ABOVE_NORMAL null THREAD_PRIORITY_NORMAL -2 THREAD_PRIORITY_BELOW_NORMAL 1 THREAD_PRIORITY_IDLE 2147483647 THREAD_PRIORITY_LOWEST -15
        The values my C acquaintance gave me are :-
        Description Process priority Thread Priority Realtime 256 15 High 128 2 Above normal 32768 1 Normal 32 0 Below normal 16384 -1 Idle 64 -2 Lowest n/a -15
        I use the following code :-
        $returncode=Win32::Process::Open($obj,$pid,0); print "\n $returncode \n"; $returncode=$obj->SetPriorityClass(THREAD_PRIORITY_LOWEST); print "\n $returncode \n";
        It returns code 0 (failure) for HIGHEST and NORMAL, 1 (OK) for BELOW, IDLE, LOWEST, but does not in fact set the Thread Priority. In fact it will only set Process Priority, and only when I give it correct values as detailed above. E.g.
        $returncode=$obj->SetPriorityClass(32);
        sets Process Priority to normal as it should. Conclusion : SetPriority does not seem able to set Thread Priority. Or am I missing something ? How do I tell it that it's a Thread Priority I'm trying to change rather than a Process Priority ? Why would the Pod text describe Thread Priority values if the routine won't use them ?
          A reply falls below the community's threshold of quality. You may see it by logging in.