fawkin has asked for the wisdom of the Perl Monks concerning the following question:

I fixed my other forking problem but have come across another. How can I ensure that if I manually "kill" my main parent process, all the other processes it creates will be killed too?

Replies are listed 'Best First'.
Re: More forking help
by kyle (Abbot) on Mar 22, 2008 at 03:04 UTC

    You could use an END block that kills the children. See perlmod for documentation for END blocks.

    I sketched out a somewhat complicated technique in Re: Keeping children alive persistiently, intelligently Basically, each child process is governed by an object that will kill it when the object is destroyed.

    Both of those have a problem in that the parent doesn't get a chance to kill its children if it receives a KILL signal (9) rather than the usual TERM (15).

    A similar question was asked in Child process dies. That thread gives suggestions for how to deal with when the parent gets a signal it can't trap.

Re: More forking help
by hipowls (Curate) on Mar 22, 2008 at 04:15 UTC

    This may help depending on your platform. On *nix boxes you can use pkill -P ppid to kill all children of the process with PID ppid. On windows there is a utility from SysInternals called pkill that can be used to kill a process and its tree. pskill -t program.