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.
source
share