Created
May 15, 2012 13:09
-
-
Save sschober/2701627 to your computer and use it in GitHub Desktop.
Test delayed signal delivery in perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use warnings; | |
use strict; | |
use POSIX qw(:signal_h); | |
my $sigset = POSIX::SigSet->new(SIGHUP); | |
my $oldset = POSIX::SigSet->new; | |
my $counter = 0; | |
$SIG{HUP} = sub { | |
print "HUP received: $counter \n"; | |
$counter++; | |
}; | |
print "$$\n"; | |
while (1) { | |
print "unblockng... "; | |
unless (defined sigprocmask(SIG_UNBLOCK, $oldset)) { | |
die "Could not unblock SIGINT\n"; | |
} | |
print "unblocked\n"; | |
sleep(5); | |
print "blocking..."; | |
unless (defined sigprocmask(SIG_BLOCK, $sigset, $oldset)) { | |
die "Could not block SIGINT\n"; | |
} | |
# signals sent here seem to be delivered eventually; | |
# multiple occurrences are cut down to just one | |
print "blocked\n"; | |
sleep(5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment