I'm not sure if beginners is the most appropriate place for this question; if not, please suggest another list.
My perl script forks and the child is subsequently replaced by another (non-Perl) program with exec(). That child has its own subprocess. In response to certain events, the parent tries to kill the child (and its children). Currently, my method for doing this is: local $SIG{HUP} = 'IGNORE'; kill HUP => -$$; This works fine when the parent is run directly from a command prompt; however, when the parent is itself called from a shell script, the child's children are not killed. The child's stdout and stderr are redirected to /dev/null; if I omit this, the above script actually works as-is, even when called from a shell script. I don't understand why redirecting output should affect the ability of the parent to kill the grandchildren, but it does. I've tried killing the child's pid as returned by fork(), as well as the negative child's pid, but neither of these kills the grandchildren when the parent is run from a shell script. If I kill the child's pid and the child's pid plus one, this works as well, but I don't think it's safe to assume the grandchild will have the child's pid plus one. I suppose I could read the output of ps -ef and grep for the child's pid to get any grandchildren's pid, but this seems like a messy way to do it. Can anyone explain: - Why redirecting the child exec script output makes it imposssible to kill the child by killing the parent process group when the parent is run from a shell script? - Why it makes a difference whether the parent is run from a shell script versus the command line? - How to list grandchildren pids without shelling out to ps? - A good solution to the problem generally? Using perl 5.8.4, Debian GNU/Linux unstable, 2.6.8-rc4 kernel. Thanks very much for any tips or URLs. -- Adam Rosi-Kessel http://adam.rosi-kessel.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>