Why isn't the child PID always parent+1 in fork()?
Issue: I noticed that the difference between the child and parent process' PIDs was different while running in Vim vs regular terminal. My code: #include<stdio.h> #include<unistd.h> int main() { pid_t child_pid; //pid_t is a data type used to represent a process id child_pid = fork(); printf("\n\nProcess: my PID is %d, and my parent is %d", getpid(), getppid()); if(child_pid 0) { printf("\nChild's pid = %d",getpid()); } else if(child_pid > 0) { printf("\nParent Pid %d",getpid()); } else { printf("fork failed"); return 1; } return 0; } Inside vim : Notice that difference between the parent and child ID is 6 -- not 1, as I had expected. # (1st time execution) Process: my PID is 10362, and my parent is 10164 Parent Pid 10368 Process: my PID is 10368, and my parent is 10362 Child's pid = 10368 Press ENTER or typ...