Skip to content

Instantly share code, notes, and snippets.

Created Apr 1, 2019
What would you like to do?
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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment