int child_pid = fork(); if (child_pid == 0) { // I'm the child process. printf("I am process #%d\n", getpid()); return 0; } else { // I'm the parent process. printf("I am the parent of process #%d\n", child_pid); return 0; } Possible output: I am the parent of process 495 I am process 495 Another less likely but still possible output: I am process 456 I am the parent of process 456