use strict; use warnings; use IO::Pipe; use IO::Select; select( ( select( STDERR ), $| = 1 )[0] ); select( ( select( STDOUT ), $| = 1 )[0] ); my $pipe = new IO::Pipe; if ( fork() ) { print "Parent live\n"; $pipe->reader(); my $ios = IO::Select->new(); $ios->add($pipe); while (1) { my $handles = scalar( $ios->handles ); my @fh = $ios->can_read(1); print( STDERR "Handles: $handles, " . scalar(@fh) . " ready\n" ); foreach ( @fh ) { print( STDERR "[r]\n" ); my $buf = ""; sysread( $_, $buf, 1024 ); print( STDERR "[d:$buf:d]\n" ); } if ( ! @fh ) { print( STDERR "[b]\n" ); } } } else { print "Child live\n"; $pipe->writer(); $pipe->autoflush(1); while (1) { $pipe->print("HELLO!"); print( STDERR "[W]\n" ); sleep 3; } }