erroneous "hello" from forked "hello world" process!
Marc Fiuczynski
mef at romulus.rutgers.edu
Mon Oct 1 11:09:47 AEST 1990
For my Operating System Design class we had to write some trivial
programs using the fork() and wait() commands. The teaching assistant
came across an interesting problem. After compiling the following:
#include <stdio.h>
main ()
{
int pid = 1;
printf("Hello\n");
pid=fork();
if(pid==0){
printf("World\n");
}
}
We should get the output:
Hello
World
however, when redirecting the output of a.out to a file and then doing a
cat on the file we would get either:
a.out > filename
cat filename
Hello
Hello
World
or
Hello
World
Hello
does anyone know what is going on? Is there a problem because there are
two processes output being redirected to the filename or what? Any help
with this would be appreciated.
--
Marc Fiuczynski
mef at remus.rutgers.edu
More information about the Comp.lang.c
mailing list