Here's the problem if you don't. In your example, the parent creates a recording channel for the child. He then expands the child, but does not close his own read handle. This means that the pipe still has two read descriptors.
If the child had one, and he closed it (for example, when exiting), the parent will receive a SIGPIPE signal or, if it was masked, an error occurred while writing to the channel.
However, there is a second read descriptor on the pipe (parent). Now, if the baby comes out, the pipe will remain open. The parent can continue to write to the channel until it is full, and then the next record will be blocked (or return without a record if it is not blocked).
Thus, without closing the parent read descriptor, the parent cannot detect that the child has closed its descriptor.
Doxylover
source share