...

View Full Version : Perl + forking



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!

bazz
11-30-2009, 11:19 PM
if that fork(); is a function can we see it? maybe the value of pid is being created differently from how you think?

bazz



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum