swartz has asked for the wisdom of the Perl Monks concerning the following question:
I have a series of test scripts that launches server subprocesses of different kinds - httpd, HTTP::Server::Simple, etc. A test script might launch multiple instances of each type of server. I'd like to behave well and kill all these children before the test exits. But it's a pain to keep track of all the child pids, especially when the code that creates the subprocess is many levels down from the test script itself.
Is there any way to automatically kill all the child processes (and their descendents) created by a script? For example, can I catch each subprocess creation somehow and record the pid in a global array? Then I could kill each pid in an END block or a Guard.
At first I tried using Proc::ProcessTable to find all the processes where ppid = $$, then kill all those processes and their children. But that doesn't work, because some servers, like httpd, launch in such a way that the parent httpd process ends up with ppid = 1.
Thanks!
|
|---|