Re: Really odd behavior of overlapping named pipes?

From: Andreas Ferber (aferber@techfak.uni-bielefeld.de)
Date: Fri Jan 25 2002 - 23:47:40 EST


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/



This archive was generated by hypermail 2b29 : Thu Jan 31 2002 - 21:00:39 EST