Reputation: 63
I have a perl script which will create a child process. I need to get the priority(nice) value for these two process(parent and child)
I can get the pid of both parent and child process as below:
$parentPID = $$;
$childPID = fork();
How to get the priority values for these process in perl script?
Upvotes: 4
Views: 961
Reputation: 50647
Check getpriority()
where first parameter for PID is PRIO_PROCESS
(you can use BSD::Resource
to import this constant or just use zero instead)
Reading current PID priority, and setting new one,
nice -7 perl -E'say getpriority(0,$$); setpriority(0,$$,9); say getpriority(0,$$)'
output
7
9
Upvotes: 4
Reputation: 13792
use the Forks::Super CPAN module. Example:
$pid = fork { os_priority => 10 }; # like nice(1) on Un*x
if you don't want to use a CPAN module, setpriority function sets the current priority for a process, a process group, or a user.
Upvotes: 2