use Fcntl; my $flags = fcntl $in, F_GETFD, 0 or die "fcntl F_GETFD: $!"; fcntl $in, F_SETFD, $flags & ~FD_CLOEXEC or die "fcntl F_SETFD: $!"; #### This is perl 5, version 18, subversion 1 (v5.18.1) built for MSWin32-x64-multi-thread #### #!/usr/bin/perl use v5.14; use warnings; #use Fcntl; my $FILE = shift or die "Need file to read\n"; # Don't set close-on-exec flag when we open a file handle local $^F = 10; say "Opening file"; open( my $in, '<', $FILE ) or die "Can't open '$FILE': $!\n"; # Clear the close-on-exec flag #my $flags = fcntl $in, F_GETFD, 0 or die "fcntl F_GETFD: $!"; #fcntl $in, F_SETFD, $flags & ~FD_CLOEXEC or die "fcntl F_SETFD: $!"; $SIG{CHLD} = 'IGNORE'; my $child_pid = fork(); if( $child_pid ) { # Parent while(1) { sleep 10 } } else { # Child say "Forking child process"; my $fd = fileno( $in ); exec( 'perl', './fd_get.pl', $fd ) or die "Could not exec: $!\n"; } #### #!/usr/bin/perl use v5.14; use warnings; my $FD = shift or die "Need file descriptor\n"; open( my $in, '<&', $FD ) or die "Could not open file descriptor '$FD': $!\n"; while(<$in>) { chomp; say "Got in child: $_"; } close $in;