Re: Rendezvous between related processes

From: Eric Sosman (Eric.Sosman_at_sun.com)
Date: 06/24/04


Date: Thu, 24 Jun 2004 13:24:26 -0400

Olivier Parisy wrote:
> Barry Margolin wrote:
>
>> It shouldn't matter when you do the dup2's.
>
>
> Is that so ? So, if a process starts reading on a pipe
> whose other end isn't connected to the standard output
> of a subprocess, it should just block, and not get an EOF ?

     Exactly.

> And, after the dup2() is performed, reading should resume
> properly ?

     The dup2() really has nothing to do with what the read()
sees. The read() will wait until somebody does a write(),
and it doesn't matter what file descriptor number is used
for the write(). You could call dup2() ninety-nine times
and give yourself a hundred file descriptors all open on
the writing end of the pipe; the read() will receive anything
you write() to any of them.

> Then I may have fixed my problem as a side effect
> of another bug pinning :-)
>
>> What do you mean by "properly set up theirs ends of pipes"? Once you
>> create the pipe, there's no special setup required.
>
>
> I just mean "to use dup2() so that they can be read or written
> to using standard IO". Would I read/write directly to the proper
> descriptors, no setup would be necessary, indeed.

-- 
Eric.Sosman@sun.com


Relevant Pages

  • Re: Pipe Fork and Exec issue
    ... I have a pppd option that allows me to tell pppd a file descriptor ... You need to close unused ends of the pipe. ... pass the fd of the reading side of the pipe as an argument to pppd. ...
    (comp.unix.programmer)
  • Re: size of pipe?
    ... Only by reading from it. ... no matter how much stuff I've written ... Say, for example, the pipe has a UNICODE- ... to-wide text converter between the two endpoints. ...
    (comp.unix.programmer)
  • Re: Pthread fd and memory leak
    ... and closes the socket file descriptor. ... When you send an fd over a pipe, the fd is still open in the sending ... memory at the pointer value and free it without errors, ...
    (comp.programming.threads)
  • Re: what happens to Popen()s parent-side file descriptors?
    ... This means that somewhere a pipe file descriptor is opened on the ... parent side to read from the child's stdout. ... to the child process, until *all* data are sent and received. ...
    (comp.lang.python)
  • Re: fd redirection and gdb
    ... When A starts, A runs pipe(), then fork, redirects file descriptors, ... stopping there, it works; A speaks, B answers; all normal. ... except maybe as a gdb bug. ... as if I were writing on the wrong file descriptor after I grabbed the ...
    (comp.unix.programmer)