#!/usr/bin/perl use warnings; use strict; use IO::Select; my $pid = open(PIP, "|-"); if ($pid < 0) { die "open(): $!"; } elsif ($pid > 0) { print scalar localtime time, " - Parent: sending something to child\n"; print PIP "Hi, son!\n"; print scalar localtime time, " - Parent: waiting for child to finish\n"; close PIP; print scalar localtime time, " - Parent: exiting\n"; } else { my $selector = IO::Select->new(\*STDIN); print scalar localtime time, " - Child: just born!\n"; sleep(60); my @handles = $selector->can_read(0); if (@handles) { print scalar localtime time, " - Child: there are " . scalar(@handles) . " handles ready for reading\n"; # It can only be STDIN... my $line = ; chomp($line); print scalar localtime time, " - Child: parent says: [$line]\n"; } print scalar localtime time, " - Child: exiting\n"; exit(0); } __END__ Sun May 22 15:43:48 2005 - Parent: sending something to child Sun May 22 15:43:48 2005 - Child: just born! Sun May 22 15:43:48 2005 - Parent: waiting for child to finish Sun May 22 15:44:48 2005 - Child: there are 1 handles ready for reading Sun May 22 15:44:48 2005 - Child: exiting Sun May 22 15:44:48 2005 - Parent: exiting