> Herve Couppe de Lahongrais - CDL wrote ...
> > Here is the execution diagram :
> > process 1
> > | fork
> > +--------->------------------------- process 2
> > | printf("hee\n") | printf("hee\n")
> > v v
> > | fork | fork
> > +--------->------- process 4 +-------->-------- process 3
> > | printf("ho\n") | printf("ho\n") | printf("ho\n") | printf("ho\n")
> > | | | |
> > x exit x exit x exit x exit
> > Output is one of the following, depending of the process scheduling:
> > hee hee hee
> > ho ho hee
> > ho hee ho
> > hee ho ho
> > ho ho ho
> > ho ho ho
> What about multiple flushings of the duplicated stdout buffers?
> I was under the impression that the child should call _exit() and not
> exit()
> to guarantee sanity. Isn't this in the FAQ?
> Richard.
In the given example, stdout buffer is flushed before fork because of
the ending new-line character '\n' in the strings "hee" and "ho".
Otherwise, it is needed to fflush(3) the buffer before calling fork(2).
--
Herve Couppe de Lahongrais (SEU) | Eurocontrol Experimental Centre