Created
May 15, 2012 15:37
-
-
Save sschober/2702711 to your computer and use it in GitHub Desktop.
Examin signal delivery behavior 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(SIGCHLD); | |
my $oldset = POSIX::SigSet->new; | |
my $counter = 0; | |
$SIG{CHLD} = sub { | |
print "SIGCHLD received: $counter \n"; | |
$counter++; | |
}; | |
print "$$\n"; | |
sub ublk { | |
print "unblocking... "; | |
unless (defined sigprocmask(SIG_UNBLOCK, $oldset)) { | |
die "Could not unblock SIGINT\n"; | |
} | |
print "unblocked\n"; | |
} | |
sub blk { | |
print "blocking..."; | |
unless (defined sigprocmask(SIG_BLOCK, $sigset, $oldset)) { | |
die "Could not block SIGINT\n"; | |
} | |
print "blocked\n"; | |
} | |
sub check_pending { | |
print "looking for pending signals..."; | |
my $es = POSIX::SigSet->new; | |
unless (defined sigpending($es)) { | |
die "Could not investigate pending signals\n"; | |
} | |
if( $es->ismember(SIGCHLD)) { | |
print " SIGCHLD pending\n"; | |
} | |
else { | |
print " no signal pending\n"; | |
} | |
} | |
my $var = "sven"; | |
while (1) { | |
check_pending; | |
blk; | |
sleep(5); | |
check_pending; | |
ublk; | |
$var .= "sven"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment