in reply to Filehandle reference lost between parent and child

Filehandles are not meant to be shared between processes. The underlying file descriptor itself may be shared, but this does not accomplish much if your idea is to arrange for inter-process communication.

For IPC, pipes or socketpairs are typically used.

  • Comment on Re: Filehandle reference lost between parent and child

Replies are listed 'Best First'.
Re^2: Filehandle reference lost between parent and child (fd)
by tye (Sage) on May 09, 2014 at 00:53 UTC
    The underlying file descriptor itself may be shared

    But not even for file descriptors does the sharing extend to the point that opening (or even closing) the FD in one process will cause the same effect on a copy of it in some related process.

    The most interesting part of the sharing (to me) is that seek() offsets are shared.

    $ cat kidseek #!/usr/bin/perl -w use strict; $| = 1; print "One\nTwo\nThree\n"; if( ! fork() ) { seek( STDOUT, 4, 0 ) or die "Can't seek STDOUT in child: $!\n"; print "Kid"; seek( STDOUT, 0, 0 ) or die "Can't again seek STDOUT in child: $!\n"; exit; } wait(); print "Dad"; $ ./kidseek >kidseek.txt $ cat kidseek.txt Dad Kid Three $

    - tye