Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How can I kill subprocesses when the main script dies?

by Anonymous Monk
on May 11, 2000 at 00:13 UTC ( #11049=perlquestion: print w/replies, xml ) Need Help??

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 };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11049]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2021-04-18 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?