open(my $in, '/etc/passwd'); my $flags = fcntl($in, F_GETFD, 0); fcntl($in, F_SETFD, $flags & (~FD_CLOEXEC)) or die "Can't set flags: $!\n"; if (!fork()) { exec("grep", "root", "/proc/self/fd/" . fileno($in)); } close($in);