Re: Really odd behavior of overlapping named pipes?

Andreas Ferber (aferber@techfak.uni-bielefeld.de)
Sat, 26 Jan 2002 05:47:40 +0100


On Fri, Jan 25, 2002 at 01:13:58PM -0500, Rob Landley wrote:
>
> int pipes[2];
>
> pipe(pipes)
> dup2(pipes[0],0);
> close(pipes[0]);
>
> Boom: the pipe is no longer usable. The stdin instance of it is closed too.
> Read from it you get an error. (But if I DON'T close it, I'm leaking file
> handles, aren't I? AAAAAAAAH!)

Did you close stdin before the pipe()? If so, the read end of the pipe
will get descriptor 0, the dup2() has actually no effect, and with the
close() you just closed stdin again.

Andreas

-- 
       Andreas Ferber - dev/consulting GmbH - Bielefeld, FRG
     ---------------------------------------------------------
         +49 521 1365800 - af@devcon.net - www.devcon.net
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/