Re: Perl Quiz of the Week #23
Ron Isaacson <Ron.Isaacson-/PgpppG8B+R7qynMiXIxWgC/[email protected]>
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
Mark Jason Dominus wrote:
>
> Mark Jason Dominnus:
> > What's happening here is that 'head' exits after printing the first
> > ten lines, and this closes the pipe. balanced_gen continues running,
> > writing data into the pipe, until the pipe becomes full.
>
> Sorry, this is mistaken. balanced_gen receives the PIPE signal as
> soon as it tries to write to the closed pipe.
Actually, I think the sigpipe happens whenever an attempt is made to
flush the output pipe. For example:
(piias845) ~: perl -e '$SIG{PIPE}=sub{die "pipe $_"}; print "." for 1..4096 ' | head -0
pipe at -e line 1 during global destruction.
My buffer is also 4096, so the program's entire output is buffered
until it exits. Exiting does an automatic flush & close of STDOUT,
bringing on the sigpipe.
(piias845) ~: perl -e '$SIG{PIPE}=sub{die "pipe $_"}; print "." for 1..4097 ' | head -0
pipe 4097 at -e line 1.
pipe at -e line 1 during global destruction.
Writing past 4096 triggers a flush and a sigpipe, and then another
when the program exits because there's still data in the pipe.
(piias845) ~: perl -e '$|=1; $SIG{PIPE}=sub{die "pipe $_"}; print "." for 1..4097 ' | head -0
pipe 1 at -e line 1.
pipe at -e line 1 during global destruction.
With $|=1, the flush is immediate on each write, so the sigpipe is
also immediate.
--
Ron Isaacson
Morgan Stanley
ron.isaacson-/PgpppG8B+R7qynMiXIxWgC/[email protected] / (212) 762-6079
NOTICE: If received in error, please destroy and notify sender. Sender
does not waive confidentiality or privilege, and use is prohibited.