Problem with broken pipe/SIGPIPE 
Author Message
 Problem with broken pipe/SIGPIPE


:When trying to write to a pipe whose read handle has been closed,
:the write command is not returning an indication of any error, and
:the script terminates.  With perl 4.0.10 (patchlevel 10), there is
:no message, and the exit status is 141.  With perl 4.0.34, there is
:a "Broken pipe" message, but there is no return from the write
:command, and the script also terminates with exit status 141.
:I'm running 4.0.10 on ConvexOS, and 4.0.34 on HP/UX.
:
:Shouldn't the write command detect an error, and allow a return?
:
:Typically, trying to write in this situation should result in the
:signal SIGPIPE being generated, and as long as this signal is either
:being ignored, or being caught and we return from the handler, the
:write system call should return with an error, and errno set to EPIPE.
:The perl write command doesn't seem to be detecting this.  What am I
:missing?  Short of writing a handler for SIGPIPE, is there anything I
:can do?  Is there a handler pre-defined for SIGPIPE?

Not unless you

    use sigtrap;

It's no different than in C, you know.  From write(2):

       EPIPE    An attempt is made to write to a pipe that is not open
                for reading by any process (or to a socket of type
                SOCK_STREAM that is connected to a peer socket.)
                Note: an attempted write of this kind also causes you to
                receive a SIGPIPE signal from the kernel.  If you've not
                made a special provision to catch or ignore this signal,
                then your process dies.

--tom
--

There are many times when you want it to ignore the rest of the string just
like atof() does.  Oddly enough, Perl calls atof().  How convenient.  :-)



Mon, 28 Apr 1997 20:33:16 GMT  
 Problem with broken pipe/SIGPIPE


[snip]

Quote:
>:Typically, trying to write in this situation should result in the
>:signal SIGPIPE being generated, and as long as this signal is either
>:being ignored, or being caught and we return from the handler, the
>:write system call should return with an error, and errno set to EPIPE.
>:The perl write command doesn't seem to be detecting this.  What am I
>:missing?  Short of writing a handler for SIGPIPE, is there anything I
>:can do?  Is there a handler pre-defined for SIGPIPE?

>Not unless you

>    use sigtrap;

>It's no different than in C, you know.  From write(2):

>       EPIPE    An attempt is made to write to a pipe that is not open
>            for reading by any process (or to a socket of type
>            SOCK_STREAM that is connected to a peer socket.)
>            Note: an attempted write of this kind also causes you to
>            receive a SIGPIPE signal from the kernel.  If you've not
>            made a special provision to catch or ignore this signal,
>            then your process dies.

>--tom

I didn't check the man page, but was using Stevens' advanced Unix
programming book.  The section I was using mentioned that the write()
command would return with an error, and set errno, but didn't mention
the process would terminate.  This was covered in another section.

(mental note: when in doubt, rtfmp - read the fine man pages ;)

I'm not sure if the best approach is to set up a handler for SIGPIPE
to trap this, or a handler on SIGCHLD since once the child dies, the
script doesn't have anyone else to play with, and I want the child's
exit status anyway.  I don't want to do both to avoid any possibility
of a race condition.

thanks again,
-steve
--
  Steven Grotten                                CONVEX Computer Corporation
  SPP Development Software Test                      3000 Waterview Parkway

  phone: 214/497-4045



Tue, 29 Apr 1997 00:44:25 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem with broken pipe/SIGPIPE

2. when pipe writer ignores SIGPIPE and other signals...

3. Broken Pipe piping to sendmail

4. Problem with an unexpected "broken pipe"

5. SIGPIPE problems w/socket

6. SIGPIPE problem with Solaris?

7. re-using a filehandle after a broken pipe

8. Pipes: What causd es them to break?

9. Broken Pipe...

10. UNIX domain socket - Broken Pipe.

11. Broken pipes error

12. Broken Pipe

 

 
Powered by phpBB® Forum Software