Pipes and File Descriptors

dealing with pipes requires the management of several file descriptors

it is important to close the unneeded file descriptors, ideally as soon as it is known that they are not needed anymore

since a process has a limit on the number of open file descriptors, it can happen that this limit is reached if file descriptors are not closed

after a fork(), the child has a copy of all file descriptors from the parent process; the ones it doesn't need should be closed right away

a process reading from a pipe will get an end of file (EOF) only after all open file descriptors to the write end have been closed; if the write end of the parent process isn't closed, the pipeline may hang forever