📌  相关文章
📜  通过分叉两次编写 ac 程序以避免僵尸进程 - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:32.998000             🧑  作者: Mango

代码示例1
#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);}