in reply to killing perl scripts

Both ysth and rev_1318 make excellent points. But, be careful with SIG handlers. 'kill -9' should be an ultimately last resort if nothing else works, not just a way to kill a script. If you read the perldoc on signals and the POSIX module POD, you should get a much better idea of what (and what not) to do.

Because I have read those, and know a bit about signals, I will mention one thing further; try to avoid setting $SIG{KILL} unless you're positive you know what you're doing. If your KILL handler doesn't work properly, you may find yourself up a very smelly stream without an appropriate nautical navigation tool. ;-)

radiantmatrix
require General::Disclaimer;
s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}

Replies are listed 'Best First'.
Re^2: killing perl scripts
by sgifford (Prior) on Dec 13, 2004 at 16:09 UTC
    On my system at least, you can't catch KILL. This code prints KILL signal caught when KILL is caught:
    [gifford@gifford gifford]$ perl -e'$SIG{KILL}=sub { die "KILL signal c +aught"; }; sleep(10)' & [1] 4316 [gifford@gifford gifford]$ kill -9 4316 [gifford@gifford gifford]$ [1]+ Killed perl -e'$SIG{KILL}=sub { die "KILL signa +l caught"; }; sleep(10)'

      Yes, that is how it should work. However, I have seen the occasional two-stage KILL signal, where kill -9 sends SIGKILL only truly destroys the process if the SIG is not handled by the application after few ticks.

      I don't know how common that is, but it's still unwise to set $SIG{KILL} unless you know for sure it will be safe to do so.

      radiantmatrix
      require General::Disclaimer;
      s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}