in reply to Signal Trapping..help please
First off, you should try writing the program and ignore signals since Perl handles interrupt signals quite gracefully by default. If that does not work, you should add signal trapping as required.
"How do I trap control characters/signals?" in perlfaq8 shows the most basic way of traping signals by using the %SIG hash. This is a very basic approach but might suffice for your purpose.
On a Unix system, I would do this:
$SIG{HUP} = \&reload; $SIG{TERM} = \&terminate; sub reload { # do whatever needs doing to restart } sub terminate { # terminate database connection, etc... }
If you need to delay signals in some portions of your code though, you might want to take a look at the sig* routines in POSIX module.
use POSIX qw(:signal_h); # do something # <criticalSection> my $sigSet = POSIX::SigSet->new; my $blockSet = POSIX::SigSet->new(SIGTERM, SIGHUP); die "Error restoring signal set: $!" unless sigprocmask(SIG_BLOCK, $blockSet, $sigSet) # do critical (uninterruptable) stuff die "Error restoring original signal set: $!" unless sigprocmask(SIG_SETMASK, $sigSet) # </criticalSection> # do other stuff here
I don't see why this wouldn't work on Windows.
|
|---|