Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created April 1, 2019 11:12
Show Gist options
  • Save hirose31/fe4b7951edfe78348bb000c5c9efd826 to your computer and use it in GitHub Desktop.
Save hirose31/fe4b7951edfe78348bb000c5c9efd826 to your computer and use it in GitHub Desktop.
#!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