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

Hello.
I am working on some code that requires open(F, "|-")...; The perlipc documentation suggests, setting SIG{ALRM}, but does not include a corresponding alarm call.
# add error processing as above $pid = open(KID_TO_WRITE, "|-"); $SIG{ALRM} = sub { die "whoops, $program pipe broke" }; if ($pid) { # parent for (@data) { print KID_TO_WRITE; } close(KID_TO_WRITE) || warn "kid exited $?"; } else { # child ($EUID, $EGID) = ($UID, $GID); exec($program, @options, @args) || die "can't exec program: $!"; # NOTREACHED }
Is there an alarm set in the background when you open(F...) or print F "blah"; or is this just an error that persists throughout all the documentation I have found?

Replies are listed 'Best First'.
Re: open(F, "|-") && SIG{ALRM}
by runrig (Abbot) on Aug 28, 2003 at 23:10 UTC
    If the program exec'd in the child process does not read or quits reading for some reason (and yet doesn't exit), then the print loop in the parent will block, so you may want to put an alarm right before the print loop. Or maybe an alarm right before the print with an 'alarm(0)' right afterward (depending on how much time you expect it to take to process the data). (and BTW, I'd say that setting the alarm handler without calling alarm anywhere is a typo in the docs)
Re: open(F, "|-") && SIG{ALRM}
by edan (Curate) on Sep 01, 2003 at 09:05 UTC

    That looks to me like a doc bug. I would guess it should read:

    $SIG{PIPE} = sub { die "whoops, $program pipe broke" };

    A broken pipe will generate a SIGPIPE signal when calling close().

    --
    3dan