Why does SIGPIPE exist?

后端 未结 5 994
梦如初夏
梦如初夏 2020-11-30 20:04

From my understanding, SIGPIPE can only occur as the result of a write(), which can (and does) return -1 and set errno to EPIPE<

5条回答
  •  囚心锁ツ
    2020-11-30 20:51

    https://www.gnu.org/software/libc/manual/html_mono/libc.html

    This link says:

    A pipe or FIFO has to be open at both ends simultaneously. If you read from a pipe or FIFO file that doesn't have any processes writing to it (perhaps because they have all closed the file, or exited), the read returns end-of-file. Writing to a pipe or FIFO that doesn't have a reading process is treated as an error condition; it generates a SIGPIPE signal, and fails with error code EPIPE if the signal is handled or blocked.

    — Macro: int SIGPIPE

    Broken pipe. If you use pipes or FIFOs, you have to design your application so that one process opens the pipe for reading before another starts writing. If the reading process never starts, or terminates unexpectedly, writing to the pipe or FIFO raises a SIGPIPE signal. If SIGPIPE is blocked, handled or ignored, the offending call fails with EPIPE instead.

    Pipes and FIFO special files are discussed in more detail in Pipes and FIFOs.

提交回复
热议问题