Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.questions Subject: Re: parent & child reading stdin Message-ID: <7968@jpl-devvax.JPL.NASA.GOV> Date: 3 May 90 17:57:39 GMT References: <46@daisy.UUCP> <7940@jpl-devvax.JPL.NASA.GOV> <48@daisy.UUCP> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Distribution: usa Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 23 In article <48@daisy.UUCP> marlon@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@jpl-devvax.jpl.nasa.gov