【发布时间】:2020-08-27 12:32:11
【问题描述】:
我想检查子进程是否/何时在 Unix 上的 C 中终止。它不应该阻塞,而是循环中的简短检查。 我的代码:
pid_t pid = fork();
if (pid > 0)
// Parent Process
while (1) {
// Do a short check whether Child has already terminated if yes break the loop.
// Ik that it's possible to use waitpid(pid, &status, 0) but that blocks the whole loop until the child has terminated
}
if (pid == 0)
printf("child process born");
exit(0);
提前谢谢
【问题讨论】:
-
乍一看,
pid = 0的分配看起来很奇怪。
标签: c unix process fork parent