Why doesn't the child process write its stdout to the pipe every time a line is created?
How do you know that? You are not even trying to read the result with fifo.
NB by file name, I assume you are using fifo . Or is it a simple file?
And a little mistake in the child: after dup2() you need close(outpipe) .
fcntl (1, F_SETFL, fcntl (1, F_GETFL) | O_NONBLOCK);
Depending on which program you are running (), you may either lose some result or cause the program to crash, because writing to stdout may now fail with EWOULDBLOCK.
IIRC fifos has the same buffer size as pipes. The minimum POSIX level is 512 bytes, usually 4K or 8K.
You probably want to explain why you need it. Non-blocking IO has different semantics compared to blocking IO, and if your child process does not expect that you will encounter different problems.
printf ("HELLO WORLD I A CHILD PROCESS \ n");
stdout is buffered, followed by fflush(stdout) . (It is not possible to find documentation if exec () itself will run stdout or not.)
Is there something I am missing in how execvp or dup2 work? I know that my approach to all of this is a bit strange, but I cannot find another way to programmatically display the output of closed source binary files.
I would not play with non-blocking IO - and left it as it is in blocking mode.
And I would use pipe () instead of fifo. The Linux man pipe has a handy example with fork ().
Otherwise, this is a fairly common practice.
Dummy00001
source share