nexus024
11-30-2009, 07:49 PM
I have a perl script that forks a command from the parent process and then kills it a few seconds later. The problem I am running into is that sometimes the process isn't killed(the script tries to kill the wrong pid). For whatever reason I am having to increment the pid of my spawned process by +1 to get the correct number. Please see the code below...
$SIG{CHLD} = 'IGNORE';
my $pid = fork();
if (not defined $pid) {
warn "resources not available.\n";
}
elsif ($pid == 0) {
exec($cmd);
exit(0);
}
else {
sleep(2);
$pid++;
kill 9, $pid;
}
Any help is much appreciated!
$SIG{CHLD} = 'IGNORE';
my $pid = fork();
if (not defined $pid) {
warn "resources not available.\n";
}
elsif ($pid == 0) {
exec($cmd);
exit(0);
}
else {
sleep(2);
$pid++;
kill 9, $pid;
}
Any help is much appreciated!