toniax has asked for the wisdom of the Perl Monks concerning the following question:
@STATE = split //, ".URRUUxR"; @data = split//,"\nrekcah xinU / lreP rehtona tsuJ"; sub make_pipe_and_fork { @pipestate{"r$fhno", "u$fhno"}=(P,P); pipe "r$fhno", "u$fhno"; ++$fhno; ($pid *= 2) += $is_child = !fork(); map { $STATE=$STATE[$is_child ^ ord($pipestate{$_}) & 6]; $pipestate{$_} = (/^$STATE/i ? $STATE : close $_); } keys %pipestate } make_pipe_and_fork; make_pipe_and_fork; make_pipe_and_fork; make_pipe_and_fork; make_pipe_and_fork; map { $pipestate{$_} =~ /^[P.]/ && close $_ } %pipestate; wait until $?; map { /^r/ ? <$_> : 1 } %pipestate; $_ = $data[$pid]; sleep rand(2) if /\S/; print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: fork process
by JavaFan (Canon) on Nov 28, 2010 at 23:35 UTC |