fork() creates a new process, copying everything in the current process to the new process. Usually this includes everything in memory and the current values of the processor registers with some minor adjustments. Thus, as a result, the new process receives a copy of the process instruction pointer, so it resumes at the same point where the original process will run (the instruction following fork() ).
To refer to your update, printf() buffered. Typically, a buffer is flushed when it encounters a newline at the end, '\n' . However, since you omitted this, the contents of the buffer remain and are not cleared. In the end, both processes (source and child) will have an output buffer with "text1" in it. When it finally turns red, you will see this in both processes.
In practice, you should always flush files and all buffers (including stdout ) before forcing to ensure that this does not happen.
printf("text1"); fflush(stdout); fork();
The result should look like this (in some order):
text1text2
text2
source share