16.20. Blocking SignalsProblemYou'd like to delay the reception of a signal, possibly to prevent unpredictable behavior from signals that can interrupt your program at any point. Solution
Use the POSIX module's interface to the To block a signal around an operation:
use POSIX qw(:signal_h);
$sigset = POSIX::SigSet->new(SIGINT); # define the signals to block
$old_sigset = POSIX::SigSet->new; # where the old sigmask will be kept
unless (defined sigprocmask(SIG_BLOCK, $sigset, $old_sigset)) {
die "Could not block SIGINT\n";
}
To unblock:
unless (defined sigprocmask(SIG_UNBLOCK, $old_sigset)) {
die "Could not unblock SIGINT\n";
}
Discussion
The POSIX standard introduced
To use use POSIX qw(:signal_h); $sigset = POSIX::SigSet->new( SIGINT, SIGKILL );
Pass the POSIX::SigSet object to See AlsoYour system's sigprocmask (2) manpage (if you have one); the documentation for the standard POSIX module in Chapter 7 of Programming Perl ![]() Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|