The new std.process is ready for review
Lars T. Kyllingstad
public at kyllingen.net
Sat Mar 9 09:36:29 PST 2013
On Saturday, 9 March 2013 at 16:05:15 UTC, Lars T. Kyllingstad
wrote:
> I think I know what the problem is, and it sucks bigtime. :(
>
> Since the child process inherits the parent's open file
> descriptors, both ends of a pipe will be open in the child
> process. We have separated pipe creation and process creation,
> so spawnProcess() knows nothing about the "other" end of the
> pipe it receives, and is therefore unable to close it.
>
> In this particular case, the problem is that "sort" doesn't do
> anything until it receives EOF on standard input, which never
> happens, because even though the write end of the pipe is
> closed in the parent process, it is still open in the child.
>
> I don't know how to solve this in a good way. I can think of a
> few alternatives, and they all suck:
>
> 1. Make a "special" spawnProcess() function for pipe
> redirection.
> 2. Use the "process object" approach, like Tango and Qt.
> 3. After fork(), in the child process, loop over the full range
> of possible file descriptors and close the ones we don't want
> open.
>
> The last one would let us keep the current API (and would have
> the added benefit of cleaning up unused FDs) but I have no idea
> how it would impact performance.
I have tried (3), and confirmed that it does indeed solve the
problem.
Lars
More information about the Digitalmars-d
mailing list