lkml.org 
[lkml]   [2002]   [Jan]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Really odd behavior of overlapping named pipes?
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/

\
 
 \ /
  Last update: 2005-03-22 13:15    [W:0.164 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site