#!/usr/bin/env perl use strict; use warnings; use autodie; $| = 1; open my $in, '<', '/etc/passwd'; my $ppid = $$; unless (fork) { print "CHILD: "; exec ("grep", "root", "/proc/$ppid/fd/" . fileno($in)); } else { print "PARENT: still going\n"; wait; } close $in; #### #!/usr/bin/env perl use strict; use warnings; use autodie; $| = 1; open my $in, '<', '/etc/passwd'; unless (fork) { print "CHILD: $_", for grep { /root/ } <$in>; print "CHILD: we're done here\n"; exit; } else { print "PARENT: still going\n"; wait; } close $in;