Canadian_Chris has asked for the wisdom of the Perl Monks concerning the following question:
# Example of pipe problem # Useage: perl pipetest.pl 2 # $ARV[0] represents how many processes to fork off, run with 2 and it + will # send a line of text from the main process and print it to STDOUT pipe READ1, WRITE1; pipe READ2, WRITE2; pipe READ3, WRITE3; pipe READ4, WRITE4; pipe READ5, WRITE5; for(1..$ARGV[0]) { $forke++; my $pid; if($pid = fork) { # parent $| = 1; $SIG{CHLD} = 'IGNORE'; if ($forke == $ARGV[0]) {&server;} } else { $| = 1; # child die "cannot fork :$!" unless defined $pid; print "Forked $forke\n"; for (;;) { $read_pipe="READ$forke"; while (<$read_pipe>) {print "Child $forke: parent said \"$_\"\n"}; } } } sub server { $t=0; for (1..5) {$t++; $write_pipe="WRITE$t"; select($write_pipe); $|=1; print "TESTING 1 2 3\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Pipe w/ fork on Win32
by jryan (Vicar) on May 31, 2002 at 05:57 UTC | |
|
Re: Pipe w/ fork on Win32
by alien_life_form (Pilgrim) on May 31, 2002 at 13:10 UTC |