#!/usr/bin/perl -w use strict; use Socket; use IO::Socket; use IO::Select; socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!"; CHILD->autoflush(1); PARENT->autoflush(1); my $pid; my $s = IO::Select->new(); $s->add(\*CHILD); if ( $pid = fork ) { close PARENT; print CHILD "Parent Pid $$ is sending this\n"; #chomp(my $line = ); my $line; while ( 1 ) { if ( $s->can_read(0) ) { foreach my $handle ( $s->can_read(0) ) { recv($handle, $line, 1024, 0); } last; } print "Waiting...\n"; } chomp $line; print "Parent Pid $$ just read this: '$line'\n"; close CHILD; waitpid($pid, 0); } else { die "cannot fork: $!" unless defined $pid; close CHILD; chomp(my $line = ); print "Child Pid $$ just read this: '$line'\n"; sleep 2; print PARENT "Child Pid $$ is sending this\n"; close PARENT; exit; }