Skip to content

Instantly share code, notes, and snippets.

@sschober
Created May 15, 2012 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sschober/2701627 to your computer and use it in GitHub Desktop.
Save sschober/2701627 to your computer and use it in GitHub Desktop.
Test delayed signal delivery in perl
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