Setting Win32 priority from within a process

C

Curufin

Hi,

Is there a simple way for a perl process to change its own priority on Win32
?
From what I understand Win32::process works only on child processes and
getpriority()/setpriority() are not available on Win32.

Thanks


Curufin
 
T

Thomas

Curufin said:
Hi,

Is there a simple way for a perl process to change its own priority on Win32
?
From what I understand Win32::process works only on child processes and
getpriority()/setpriority() are not available on Win32.

Win32::process is the right module. Use something like this:

use Win32;
use Win32::process;

my(%PVal) = (
IDLE => IDLE_PRIORITY_CLASS,
HIGH => HIGH_PRIORITY_CLASS,
NORMAL => NORMAL_PRIORITY_CLASS,
REALTIME => REALTIME_PRIORITY_CLASS,
);

sub SetOwnProcessPriority {
my($prio) = @_;

my($obj);
Win32::process::Open($obj, $$, 0);

unless ($obj) {
print "error creating Win32::process object",
Win32::FormatMessage(Win32::GetLastError());
return;
}

unless ( $obj->SetPriorityClass($PVal{$prio}) ) {
print "error setting process priority $prio\n",
Win32::FormatMessage(Win32::GetLastError());
return;
}

print "successfully set process priority to $prio\n";
}

then you can use:

SetOwnProcessPriority('IDLE');

somewhere in your script.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top