parent & child reading stdin
Larry Wall
lwall at jpl-devvax.JPL.NASA.GOV
Fri May 4 03:57:39 AEST 1990
In article <48 at daisy.UUCP> marlon at daisy.com (Marlon Pearson) writes:
: As to the third from the end sentence. I understand that it is a fairly
: common practice when passing info between a parent and child to set up
: a pipe or pipes where one process writes to the pipe and the other
: reads from it. So, I thought this may be an alternative to what I
: current have working. The parent would read from stdin and after it had
: consumed the first N bytes it would simply pass the remaining byte
: stream to the child via writing to the pipe. The child would read from
: the pipe instead of stdin.
That would only be possible if the stdin was already connected to a pipe and,
somehow, the parent had access to the write end of the stdin pipe, which is
generally not the case. Pipes are two ended and directional, and stdin
will be connected only to the read end. Writing on stdin is normally frowned
upon.
To do what you want you'll have to close stdin and set up a pipe of your own
with the read end on descriptor 0. After you fork, that'll be the child's
stdin. The parent hangs on to the other end of the pipe, which has its own
descriptor, and writes to that end.
Larry Wall
lwall at jpl-devvax.jpl.nasa.gov
More information about the Comp.unix.questions
mailing list