Created
April 1, 2019 11:12
-
-
Save hirose31/fe4b7951edfe78348bb000c5c9efd826 to your computer and use it in GitHub Desktop.
This file contains 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
#!perl | |
use strict; | |
use warnings; | |
# use POSIX; | |
my($p, $c); | |
pipe($p, $c); | |
if (fork() == 0) { | |
print "child $$\n"; | |
close $p; | |
sleep 2; # write to pipe after timeout | |
print $c "42\n"; | |
exit 0; | |
} | |
print "parent $$\n"; | |
local $SIG{ALRM} = sub{ | |
print "timeout\n"; | |
open my $fh, '<', '/etc/passwd' or die $!; | |
while (<$fh>) {} | |
close $fh; | |
}; | |
alarm 1; | |
close $c; | |
print while <$p>; | |
while (wait() != -1) {} | |
print "done\n"; | |
__END__ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment