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 ...
  • Re: loss of data on pipes
    ... > child processes, ... > and child and, on the child, ... > fcntlthe pipe to be stdout. ...
  • 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. ...
  • 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. ...
  • Re: Problems with redirect and format stdout and stderr for CreateProcess
    ... strings in the beginning and end of stdout and stderr. ... not fail but it always returns that there is no data in the pipe. ... unsigned long bread; //bytes read ...