reading and writing to another process

moss at brl-vld moss at brl-vld
Thu Oct 6 22:51:56 AEST 1983


From:      Gary S. Moss (301)278-6647 <moss at brl-vld>

In practice, it is best to set up a batch operation requiring only
one pipe. The parent writes to a temporary file, then forks.
The child reads from that file rather than from a pipe
(just substitute the file descriptor for the pipe descriptor
in the fcntl(2) or dup(2) system calls). The parent, immediately
after forking reads from the pipe.

This way, the child does not block during reading so there
is no chance for a deadlock.  This does not allow a true
conversation to occur because when the child hits an EOF,
it will terminate, however, it is sufficient for most
applications. The thing to watch out for is that a process
writing on a pipe will block if the buffer gets full and
nobody is reading from it. Therefore, the parent should
finish writing to the child so that it can be reading
from it before the child starts writing.

Setting up communications protocols will not work as a solution
to the original question because the child is blind to the whole thing.
- Moss.



More information about the Comp.unix mailing list