#! perl -sw
use 5.010;
use strict;
use Inline C => Config => BUILD_NOISY => 1;
use Inline C => <<'END_C', NAME => 'Priority', CLEAN_AFTER_BUILD => 0
+;
HANDLE openProcess( SV *pid ) {
HANDLE ph;
if( !( ph = OpenProcess( PROCESS_ALL_ACCESS, 0, SvIV( pid ) ) ) )
croak( "Failed to open process pid:%d (See $^E)\n", SvIV( pid
+) );
return ph;
}
SV *setPriorityClass ( SV *pid, SV* class ) {
HANDLE ph = openProcess( pid );
if( !SetPriorityClass( ph, SvUV( class ) ) )
croak( "SetPriorityClass failed; See $^E \n" );
return class;
}
int getPriorityClass ( SV *pid ) {
HANDLE ph = openProcess( pid );
DWORD class;
if( !( class = GetPriorityClass( ph ) ) )
croak( "SetPriorityClass failed; See $^E \n" );
return class;
}
END_C
use constant PRIORITY => {
IDLE => 0x40, BELOW => 0x4000, NORMAL => 0x20,
ABOVE => 0x8000, HIGH => 0x80, REALTIME => 0x100,
};
my $old = eval{
getPriorityClass( $ARGV[ 0 ] )
} or die $^E;
my $new = eval{
setPriorityClass( $ARGV[ 0 ], PRIORITY->{ uc $ARGV[ 1 ] } )
} or die $^E;
say "Priority of process id: $ARGV[ 0 ] changed from $old to $new";
__END__
C:\test>priority 1460 idle
Priority of process id: 1460 changed from 32 to 64
C:\test>priority 1460 below
Priority of process id: 1460 changed from 64 to 16384
C:\test>priority 1460 normal
Priority of process id: 1460 changed from 16384 to 32
C:\test>priority 1460 above
Priority of process id: 1460 changed from 32 to 32768
C:\test>priority 1460 high
Priority of process id: 1460 changed from 32768 to 128
C:\test>priority 1460 realtime
Priority of process id: 1460 changed from 128 to 256
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|