📅  最后修改于: 2022-03-11 14:58:32.998000             🧑  作者: Mango
#include#include #include#includeint main(){pid_t pid;if ((pid = fork()) < 0){printf("fork error");}else if (pid == 0){ /* first child */if ((pid = fork()) < 0)printf("fork error");else if (pid > 0)exit(0);sleep(2);printf("second child, parent pid = %d\n", getppid()); exit(0);}if (waitpid(pid, NULL, 0) != pid) /* wait for first child */printf("waitpid error");exit(0);}