terminating fifo in perl

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Calling main.sh will hang. I think that this is related with the fifo.
Does anybody know a way to make the code finish without hanging?

~/linux/bin/xplat/src/coreutils/backup/headbody/perl/fifo/main$ cat
#!/usr/bin/env bash

rm -rf head body
mkfifo head body
seq 10 | ../headbody.pl head body &
cat head body &

~/linux/bin/xplat/src/coreutils/backup/headbody/perl/fifo/main$ cat ../
#!/usr/bin/env perl

use strict;
use warnings;

#use FindBin;
#use lib "$FindBin::Bin/.";

open(HEAD, '>', $ARGV[0]) or die "cannot to open $ARGV[0] $!";
open(BODY, '>', $ARGV[1]) or die "cannot to open $ARGV[0] $!";

my $head = <STDIN>;
print HEAD $head;
close(HEAD) or die "cannot to close $ARGV[0] $!";

print STDERR "head";

while(<STDIN>) {
  print BODY;
close(BODY) or die "cannot to close $ARGV[1] $!";

print STDERR "body";


Re: terminating fifo in perl

Quoted text here. Click to load it

Opening a fifo for writing will block until someone opens it for
reading. cat will not open body for reading until after it has finished
reading from head, and headbody.pl will not close head until after it
has opened body. Either close head before opening body, or open the
fifos read-write (which will not block).


Site Timeline