erroneous "hello" from forked "hello world" process!

Jay A. Konigsberg jak at sactoh0.SAC.CA.US
Tue Oct 2 11:56:44 AEST 1990


>In article <Sep.30.21.09.46.1990.2881 at romulus.rutgers.edu> mef at romulus.rutgers.edu (Marc Fiuczynski) writes:
>#include <stdio.h>
>
>main ()
>{
>printf("Hello\n");
>if(fork()==0)
>    printf("World\n");
>}
>

This is an excerise from chapter 7 in Bach's "Design on the Unix O/S".
The goal isn't to know how to correct the output, but to describe
why it acts the way it does.

Several people have already talked about stdio being buffered and fork()'s
child inheriating the file descriptors, so I won't re describe it.

However, there are lots of neat excersies in this book. Perhaps more
of them should be posted?

-- 
-------------------------------------------------------------
Jay @ SAC-UNIX, Sacramento, Ca.   UUCP=...pacbell!sactoh0!jak
If something is worth doing, it's worth doing correctly.



More information about the Comp.lang.c mailing list