http://www.perlmonks.org?node_id=11049

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

using IIS(ew!!) and the occassionally it timeouts my perl script. however the processes started by my perl script keep going. i know how to get the PIDs for them, but is there a generic way to kill them before the outside program (IIS) kills my script? thanks

Originally posted as a Categorized Question.

  • Comment on How can I kill subprocesses when the main script dies?

Replies are listed 'Best First'.
Re: How can I kill subprocesses when the main script dies?
by chromatic (Archbishop) on May 11, 2000 at 01:17 UTC
    Maybe an END block:
    END { kill 'INT' => keys %children; }
    If you keep the PIDs for your kids in %children, that'll do it. For example, the following script dies, but still prints the ending notice:
    #!/usr/bin/perl -w use strict; BEGIN { print "This is at the start\n"; } die; print "This is in the middle.\n"; exit; print "This should never print.\n"; END { print "This is in the end.\n"; }
Re: How can I kill subprocesses when the main script dies?
by merlyn (Sage) on May 11, 2000 at 02:10 UTC
    An END block won't be executed unless a signal handler has been established, even if the signal handler simply dies.

    The briefest way to do that is something like:

    $SIG{INT} = sub { die };