#include #include #include int main(void) { // fork creates 2 identical copies of program // only return value is different pid_t pid = fork(); if (pid == -1) { perror("fork"); // print why the fork failed } else if (pid == 0) { printf("Child...\n"); printf("C: my pid is %d.\n", getpid()); printf("C: my parent is %d.\n", getppid()); printf("I am the child because fork() returned %d.\n", pid); sleep(6); } else { printf("Parent...\n"); printf("P: my pid is %d.\n", getpid()); printf("P: my parent is %d.\n", getppid()); printf("I am the parent because fork() returned %d.\n", pid); //Don't care about child exit status so passing in NULL if (waitpid(pid, NULL, 0) < 0){ perror("Wait: "); return 1; } printf("My child process has terminated\n"); sleep(300); } return 0; }