parent & child reading stdin

Marlon Pearson marlon at daisy.UUCP
Thu May 3 02:38:24 AEST 1990


:In article <46 at daisy.UUCP> marlon at daisy.UUCP (Marlon Pearson) writes:
:: My understanding is that you can't guarantee who gets which bytes when
:: you have two processes reading from the stdin at the same time. Is it a 
:: bad idea if I have a parent process that will read the first N bytes and then
:: fork and exec a child process and let it read the rest of stdin? I have tried
:: this with out doing any dups or pipes or such for passing bytes from the
:: parent to the child. The child inherits the stdin from its parent and reads
:: it fine. As I said, it seems to work and makes sense but is it the "correct"
:: way of doing it.

:It better be correct, since the shells do that all day long.

:The distinction to be made is that, since "correct" programs are using the
:fork as a synchronization point, they are NOT, in fact, "two processes
:reading from stdin at the same time."

:Though I don't know what you mean by your antepenultimate sentence.  In
:what way are you using stdin to pass bytes from the parent to the child?
:That doesn't fit in with the rest of what you are asking.

:Larry Wall

Larry,

Thanks for the response.
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.

Marlon


-- 
===========================================
Marlon
{nsc,atari,pyramid,uunet}!daisy!marlon



More information about the Comp.unix.questions mailing list