Buffering.
Since the standard output on your system is buffered by default, it does not print immediately. The buffer, however, will be flushed before the process exits.
Since fork copies the full memory space of the parents, the state of the file descriptor, etc., it also copies the buffer data that needs to be printed.
Thus, if you do not explicitly flush the standard output buffer before forcing (by adding \n to the output or calling fflush(stdout); ), both processes will have buffered output for printing. A.
source share