Visually what happens to fork() in a For Loop
问题 I have been trying to understand fork() behavior. This time in a for-loop . Observe the following code: #include <stdio.h> void main() { int i; for (i=0;i<3;i++) { fork(); // This printf statement is for debugging purposes // getppid(): gets the parent process-id // getpid(): get child process-id printf("[%d] [%d] i=%d\n", getppid(), getpid(), i); } printf("[%d] [%d] hi\n", getppid(), getpid()); } Here is the output: [6909][6936] i=0 [6909][6936] i=1 [6936][6938] i=1 [6909][6936] i=2 [6909]