Why does writing to an unconnected socket first send SIGPIPE?

There are so many possible errors in a POSIX environment. Why do some of them (for example, writing to an unconnected socket in particular) receive special treatment in the form of signals?

+3
source share
4 answers

This is by design, so simple text-generating programs (such as find, grep, cat) used in the pipeline will die when their consumer dies. That is, if you use a type chain find | grep | sed | head, the head will exit as soon as it reads a sufficient number of lines. This will kill sed with SIGPIPE, which will kill grep with SIGPIPE, which will kill find with SEGPIPE. If there was no SIGPIPE, naively written programs continued to work and create content that was not needed.

If you do not want to receive SIGPIPE in your program, just ignore it by calling signal (). After that, syscalls such as write (), which fall into the broken channel, are returned using errno = EPIPE.

+4
source

. SO , / SIGPIPE.

TCP- , ?

+1

SIGPIPE — , , ( ). , , ( , , , , ).

less. stdin ( ) . , stdin . , , (, q) , . , , , .

0

.

in the beginning, people use the signal to control the notification of events that were sent to user space, and later this is not necessary because there are more popular skeletons, such as polling, which does not require the system caller to call the signal handler.

0
source

Source: https://habr.com/ru/post/1720382/


All Articles