I'm definitely a Linux coding newbie but I haven't seen this addressed
in the FAQ so hopefully you guys can help me out.
I have a parent process that forks() off a child, directs the child's
stdout and stderr to a parent-owned pipe, and then execs() an
arbitrary program. Obviously this is the kind of thing that is done
all the time in Linux-land. :-)
Because I need to reserve the right to kill the child if it's around
too long, the parent needs to read() the pipe in a non-blocking
fashion. I choose to use poll() to help facilitate this but I suspect
that using fcntl() to put the pipes into non-blocking mode would have
worked too (is one way better than the other?). All of this works
The problem is when the output from the child process is intermittent.
What I'm currently seeing is that I can read nothing from the pipe
until the child completes. In my test case the amount of output is
very small (a K or so) and the child is writing it to stdout slowly,
say a line every few seconds. I really need my parent process to read
the lines as they are generated by the child, and not all in one bunch
at the end.
Any help or advice would be greatly appreciated. Thanks!