I'm surprised that SIGPIPE is not mentioned (and barely present in comments). It's 90% of why I'm scared of signals and every time I write something mixing IO and threads it eventually rears its disgusting head. Can someone shine a light on what the heck it's designed to do?
The earlier part tries to write, gets `0` or `-1` with an error, concludes the pipe is closed, and exits? The doc for `write` even specifies the error code `EPIPE` that is set alongside with the `SIGPIPE`. Why the signal, when it's redundant?