using namespace std; #include #include #include #include #include int main(int argc, char * argv[]) { int pid; pid = fork(); if (pid == 0) { printf("I am the child, my process id is %d\n",getpid( )); printf("the child’s parent process id is %d\n",getppid( )); sleep(20); printf("I am the child, my process id is %d\n",getpid( )); printf("I am the child, parent's process id is %d\n",getppid( )); } else { printf("I am the parent, my process id is %d\n",getpid( )); printf("the parents parent process id is %d\n",getppid( )); } }