[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.


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