in reply to Re: Leaking a file descriptor into a child to use with /proc/self/fd/3
in thread Leaking a file descriptor into a child to use with /proc/self/fd/3

Perfect, that fixed the problem. I did not realize Perl closed FDs on exec (or maybe that is an OS thing).

  • Comment on Re^2: Leaking a file descriptor into a child to use with /proc/self/fd/3

Replies are listed 'Best First'.
Re^3: Leaking a file descriptor into a child to use with /proc/self/fd/3
by Your Mother (Archbishop) on Feb 26, 2020 at 23:55 UTC

    The Perl process essentially goes away by replacing itself when you exec. So, it might feel surprising but it seems sensible/intuitive that any FDs opened in Perl would close.

Re^3: Leaking a file descriptor into a child to use with /proc/self/fd/3
by ewheeler (Novice) on Feb 26, 2020 at 23:59 UTC

    This worked:

    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);