Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use Carp; use Data::Dumper; use English '-no_match_vars'; use FileHandle; $| = 1; my $no_of_childs = 3; my @fh; my $index = 0; while ($index < $no_of_childs) { print "PID $PID\n"; my $pid; $fh[$index]{'fh'} = new FileHandle; $fh[$index]{'fh'}->autoflush(1); $pid = $fh[$index]{'fh'}->open("|-"); if ($pid) { # parent $fh[$index]{'pid'} = $pid; print "parent pid $PID creating child " . $index+ ++ . "\n"; } else { # child print "child pid $PID creating child " . $index++ . "\n +"; while (1) { # Here we will do the child work, and read inpu +t from STDIN print "$PID checking for input\n"; my $line = <STDIN>; if ($line) { print "$PID got something from father ! +!! $line\n"; } sleep 1; } exit; } } print Dumper \@fh; my $fh; sleep 5; $fh = $fh[0]{'fh'}; print "send hi to child 1\n"; print $fh "shalom yeled 1"; sleep 2; $fh = $fh[1]{'fh'}; print "send hi to child 2\n"; print $fh "shalom yeled 2"; sleep 2; $fh = $fh[2]{'fh'}; print "send hi to child 3\n"; print $fh "shalom yeled 3";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interprocess using Safe Pipes Opens
by liverpole (Monsignor) on Aug 02, 2007 at 17:10 UTC | |
|
Re: Interprocess using Safe Pipes Opens
by krishnoid (Novice) on Aug 02, 2007 at 22:56 UTC |