Mailing List Archive

Re: pclose bug in 5.001m or BSDI 2.0 bug... You decide.
> Under BSDI 2.0 (gcc 1.42 compiled), I run into the folowing:
>
> perl -le 'open(P,"cat /etc/passwd|");$x=<P>;close(P)||die("Fail: $?")'
>
> prints "Fail: 13". Why? Well, it would seem that, contrary to the
> docs, perl is doing a non-blocking wait on the process.

Happens on SunOS 4.1.4 and Ultrix 4.3 too, both with perl 4.036 and 5.001m.
(That is, I had to replace `cat /etc/passwd' with `yes foo' which
doesn't terminate that quickly:-)

Since it seems so well-established, maybe it should be called a doc
bug - and the function `wait FILEHANDLE' could be used to wait instead...

I suspect it would break and/or slow down a lot of programs to fix this
now. If you fix it, at least add something to avoid deadlock: Perl
waiting for the process, which waits for perl to drain the pipe so it
can write some more output.


Regards,

Hallvard
Re: pclose bug in 5.001m or BSDI 2.0 bug... You decide. [ In reply to ]
: > Under BSDI 2.0 (gcc 1.42 compiled), I run into the folowing:
: >
: > perl -le 'open(P,"cat /etc/passwd|");$x=<P>;close(P)||die("Fail: $?")'
: >
: > prints "Fail: 13". Why? Well, it would seem that, contrary to the
: > docs, perl is doing a non-blocking wait on the process.
:
: Happens on SunOS 4.1.4 and Ultrix 4.3 too, both with perl 4.036 and 5.001m.
: (That is, I had to replace `cat /etc/passwd' with `yes foo' which
: doesn't terminate that quickly:-)

There's a reason for that. See below.

: Since it seems so well-established, maybe it should be called a doc
: bug - and the function `wait FILEHANDLE' could be used to wait instead...

Won't make any difference.

: I suspect it would break and/or slow down a lot of programs to fix this
: now. If you fix it, at least add something to avoid deadlock: Perl
: waiting for the process, which waits for perl to drain the pipe so it
: can write some more output.

No, it is doing a blocking wait. However, there's nothing to wait for,
since the subprocess is dying from a SIGPIPE (signal 13) because the
other end of its pipe was closed. The difference in behavior is
reflective of how much buffering the system is doing, and how big the
passwd file is. The subprocess can think it has finished normally even
though the parent process has only read one line.

Larry