#!/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"; }