Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
If I use an external command such as open(FILE, '| cat') it works fine, but deadlocks with the forked pipe version. Any ideas?our @handles; our $message = ('xxxxxxxx'); sub child { my $buffer; while(sysread(STDIN, $buffer, 8)) { print("$$: $buffer\n"); } } for($i=0; $i < 4; $i++) { if(!open($handles[$i], '|-')) { # child process child(); exit 0; } } for($i=0; $i < 4; $i++) { syswrite($handles[$i], $message); syswrite($handles[$i], $message); syswrite($handles[$i], $message); } for($i=0; $i < 4; $i++) { close($handles[$i]); } Produces the following output then freezes: 18241: xxxxxxxx 18241: xxxxxxxx 18241: xxxxxxxx 18242: xxxxxxxx 18242: xxxxxxxx 18242: xxxxxxxx 18243: xxxxxxxx 18243: xxxxxxxx 18243: xxxxxxxx 18244: xxxxxxxx 18244: xxxxxxxx 18244: xxxxxxxx
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Forked pipe deadlock
by pc88mxer (Vicar) on May 25, 2008 at 20:50 UTC | |
by almut (Canon) on May 25, 2008 at 21:33 UTC | |
by psini (Deacon) on May 25, 2008 at 20:55 UTC | |
by Anonymous Monk on May 25, 2008 at 21:35 UTC | |
|
Re: Forked pipe deadlock
by pc88mxer (Vicar) on May 25, 2008 at 21:31 UTC | |
|
Re: Forked pipe deadlock
by psini (Deacon) on May 25, 2008 at 21:20 UTC |