I'm not sure I completely understand your problem, but I usually use the "piped-open" form of forking,
my $pid = open(PH, "ls &|");
to get a real $pid, which you can then kill later. I've found that sometimes, the pid you get is the shell, so you need to be aware of the ppid....
brutally stop a perl program if it runs too long. I've even seen some cases like forking of mplayer, where you get the ppid from the piped open, then mplayer will fork, so you need to kill all the children of the ppid.
#!/usr/bin/perl
use warnings;
use strict;
#robau
#This subroutine takes two arguments, the parent process ID
#and the numeric signal to pass to the processes
#(which would be 9 if you wanted to issue a -TERM).
#Using Proc::Process you could find the process ID
#of the process login -- zentara with something similar
#to the following :
#my $proc = Proc::ProcessTable->new;
#my @ps = map { $_->pid if ($_->cmndline =~ /login -- zentara/) } @{$p
+roc->table};
#&killchd($_, 9) foreach @ps;
&killchd(9895, 9);
#kill -9 process 9895
sub killchd ($;$) {
use Proc::ProcessTable;
my $sig = ($_[1] =~ /^\-?\d+$/) ? $_[1] : 0;
my $proc = Proc::ProcessTable->new;
my %fields = map { $_ => 1 } $proc->fields;
return undef unless exists $fields{'ppid'};
foreach (@{$proc->table}) {
kill $sig, $_->pid if ($_->ppid == $_[0]);
};
kill $sig, $_[0];
};