in reply to Perl action on cancellation
It depends on how the script is being killed. A kill -9 on unix can not be trapped, nor can someone pulling the plug out the wall. That aside you can set a signal handler, here is an example that traps the Ctrl-C by setting the $SIG{INT} handler to a subroutine reference. It also has an END block just for fun (any cleanup you do in normal termination could be here and it will get run after the sig handler)
$ perl -le'$SIG{INT}=sub{print "cleanup"};sleep 100;END{print "goodbye +"}' # here I hit Ctrl-C cleanup goodbye $
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl action on cancellation
by tirwhan (Abbot) on Feb 08, 2005 at 12:55 UTC | |
|
Re^2: Perl action on cancellation
by Win (Novice) on Feb 08, 2005 at 12:15 UTC | |
by Random_Walk (Prior) on Feb 08, 2005 at 12:22 UTC |