Frequently Asked Question

What is SIGPIPE and why do I sometimes see 'broken pipe' errors?

When the reader at the end of a pipe closes its descriptor, perhaps because it finished its work, perhaps because it crashed, the kernel sends SIGPIPE to any process that subsequently writes to that pipe. The default action for SIGPIPE is to terminate the writer silently. If the writer chooses to ignore the signal, the write call instead fails with EPIPE, which the program may report as "Broken pipe".

This shows up most often with head: yes | head -1 exits cleanly because the kernel kills yes once head has closed its end. But find / | grep something | head -1 may produce a "Broken pipe" message at script exit, because find keeps running for a moment after head is gone and its next write fails. The signal is a feature, not a bug, it's how the pipeline tells the producer to stop wasting effort. It also explains why scripts that pipe into long-running tools need to handle the signal themselves if they want to do cleanup.

Further reading and video