[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: fork or printf problem



Put, fflush(stdout), after the printf("Hello\n") statement. You will get
same result. The first "hello" is buffered and not printed and when it
forks, the child also gets a copy of that buffer. Thats why one extra
hello is printed.

bye,
saugata


:running the output executable of the following program as
:
:$a.out
:and
:$a.out > test
:
:give different results
:WHY??
:
:****************************
:#include <stdio.h>
:#include <sys/types.h>
:#include <unistd.h>
:
:main()
:{
:
:    printf("Hello\n");
:    if(fork()==0)
:    {
:        printf("world\n");
:    }
:}
: