Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to do this:

do {
    $pid = open(KID_TO_WRITE, "|-");
    unless (defined $pid) {
        warn "cannot fork: $!";
        die "bailing out" if $sleep_count++ > 6;
        sleep 2;
    }
} until defined $pid;

This will fork a child which can read STDIN for the contents written by the parent to KID_TO_WRITE.

How can I make my writes to KID_TO_WRITE block? I would like the parent's progress writing lines to somewhat reflect the progress of the child reading the pipe.

Basically, I'd like this to work as if I wrote to a fifo (mknod). But, without the visibility of the fifo (for security reasons).

Thanks!
Mark

  • Comment on How to make interprocess pipe blocking?

Replies are listed 'Best First'.
Re: How to make interprocess pipe blocking?
by ikegami (Patriarch) on Oct 03, 2004 at 02:16 UTC
    Maybe you're looking for autoflush?
    { my $h = select(KID_TO_WRITE); $|=1; select($h); }