Re: questions about pipe




pankajtakawale wrote:
I have a parent process, which pulls stdout of its child process using
pipe (child process's stdout is redirected to write end of pipe)

I have few doubts about the pipe mechanism:

parent code:

//other parent code;

while(read from read-end of pipe)
{
process read data;
}


1. what if child process flushes some data to stdout & breaks pipe
(either by exiting or explicitly closing stdout), even before parent
calls 'read on read-end of pipe'?

In this case, read would fail as other end of pipe is broken,
right? or does it able to read data flushed by child process and then
it would see broken pipe and then come out of read?

2. If Parent is in the middle of processing 'read data', and child
flushed data to stdout & exited (i.e. broke wite-end of pipe)

In this case, next read after processing would be able to read data
from pipe and process it. Then next read would see broken pipe and
returns error, right?

In both the cases, read() will return all the data written to the pipe
before its write end has been closed. When no data is available and the
write end is closed read() will return 0 (EOF).

.



Relevant Pages

  • Re: Asynchrounous Standard Output Capture - regarding
    ... I need to capture the outout when running as a separate console (lets ... // Set the bInheritHandle flag so pipe handles are inherited. ... // Create a pipe for the child process's STDOUT. ... I cannot find a single line of documentation that says that a child process inherits its ...
    (microsoft.public.vc.mfc)
  • Re: loss of data on pipes
    ... > child processes, ... > and child and, on the child, ... > fcntlthe pipe to be stdout. ...
    (comp.unix.programmer)
  • Re: Getting both PID and output from a command
    ... Getting both PID and output from a command ... > One problem is that the stdout and stderr are merged into a single stream. ... I wouldn't trust using a pipe. ... > child to flush it's stdout. ...
    (comp.lang.python)
  • 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: Program hanging when read()ing from pipe
    ... stderr (because it fills the pipe buffer) while your program is blocked ... so I'll have to do it at least for stderr. ... child's stdin and the child blocks writing to stdout. ...
    (comp.unix.programmer)