How to find pid of PS which executed by perl system function

hello All,

I need to invoke by perl script some program/command and monitor it for 5
minutes . In case it still running for more then 5 min I need to send a signal which will stop it.

I implemeted this as shown below by using eval & alarm
and I'd like to know if there is a better way to find the PID of the PS which I executed by calling system , with perl command , instead of grep the ps command ?

Thanks in Advance.

eval {
local $SIG{ALRM} = sub {die "died in SIG ALRM";};
alarm(10);
`./time.pl | tee -a $log`;
alarm(1); # Somehow alarm(0) cause the prgram to get stuck
$i++ while 1;
};
print "out from eval\n";
if ($@) {
if ($@ =~ /died in SIG ALRM/) {
$ps = `ps -ef |grep user |grep time.pl |grep -v grep|grep -v nedit |grep -v "tee" |tr -s " " " " | cut -f2 -d " " `;
chomp $ps;
print "ps = $ps\n";
if($ps ne ""){
if(kill 0 => $ps){print "process : $ps is alive\n";}
kill 1 , $ps;
sleep(1);
if(kill 0 => $ps){print "process : $ps is alive\n";}
elsif($! == EPERM)
{
print "process $ps has escaped my control\n";
}
elsif($! == ESRCH)
{
print "prosess : $ps has deceased\n";
}
else
{
print "Odd: Icouldn't check the status of $c_pid\n";
}
}
}
else {
print $@;
}
}
}

These lines look wrong:

f(kill 0 => $ps){print "process : $ps is alive\n";}
kill 1 , $ps;
sleep(1);
if(kill 0 => $ps){print "process : $ps is alive\n";}

the "=>" operator should be ">=" to compare values. "=>" is the comma operator that is used for a different purpose.

I know there are modules you can use to check pids but I don't know if they are anymore efficient than your method. Hopefully someone else will have a suggestion.