Ticket #2220 (closed bug: duplicate)
Subprocesses do not close open FDs
When creating a subprocess, for example with runInteractiveProcess, only pipes that are created in the process of creating the process are closed appropriately; any FDs created elsewhere in the program are ignored. As unix pipes are only considered closed once every process that could conceivably write to one has closed it, one consequence of this is that programs that rely on detecting EOF will be unable to do so. Another is that the system may leak FDs over the runtime of the program, conceivably running out.
As an example, this makes it impossible to write a fully functional shell with pipes in GHC; in a shell command like "<main program> | cat | cat", the second cat may acquire a reference to the pipe used for writing to the first one, which will prevent that pipe from ever being considered closed.
A brute-force solution would be to attempt to close every possible FD when creating subprocesses. This is undesirable for several reasons - most obviously performance, but also because there are legitimate reasons to pass FDs other than stdin/out/err to a subprocess. A more elegant one would be for all FDs opened by any means to be marked as close-on-exec on creation, and provide a call to clear this bit if transferring it to a specific subprocess is desired.