Operating System - HP-UX
1832964 Members
2463 Online
110048 Solutions
New Discussion

Re: How to check processes from a PERL program?

 
SOLVED
Go to solution
Enrico Venturi
Super Advisor

How to check processes from a PERL program?

Hello colleagues,
I'm new to PERL (even if I'm 41)
then I need some help to do my 1st program.
In my PERL program I fork several children, and I want to keep them under control, i.e. I want to know if they are still running at a certain moment.
I want to be as much efficient as possible.
I'd like to avoid "system" or ' ' calls.
Is there any PERL call to check a process PID?
Or can I receive a signal when a child dies?

thanks for any help
Enrico
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How to check processes from a PERL program?

When you fork(), you should capture the PID of each child process. Then to determine is the process is still running, one easy method
is
$rslt = kill 0,$child_pid;
if ($rslt)
{
print "Child ",$child_pid," is still running.\n";
}

Signal handling is easy too:

sub child_process
{
print "Child sent signal\n"
return(-1)
}

$SIG{TERM} = \&child_process;

Now if the child sends a SIGTERM to the parent pid the parent can act on it.
If it ain't broke, I can fix that.