Skip to content

Instantly share code, notes, and snippets.

@hirose31

hirose31/ENOMEM.pl

Created Apr 1, 2019
Embed
What would you like to do?
#!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