That's standard behavior. You close the read-end of the pipe, so there is nowhere to write. That results in a SIGPIPE
signal being sent to the writing process.
The default behavior of SIGPIPE
is to terminate the process receiving the signal.
If you want your process to survive the signal, you have to catch or ignore it. Then you must check the result of write
as it will return with an error when the pipes read-end is closed.