/* * fork2.c */ #include #include int main(int argc, char *argv[]) { pid_t child_pid, parent_pid; child_pid = fork(); if(child_pid == 0) { printf("I am the child and fork returned %d.\n", child_pid); child_pid = getpid(); printf("Wait, no, I am the child and my pid is %d.\n", child_pid); } else { parent_pid = getpid(); printf("I am the parent and my child's pid (fork returned) is %d.\n", child_pid); printf("My (the parent) pid is %d.\n", parent_pid); } }