- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
for (; 1;) {
if (fork() == 0) break;
int sig = 0;
for (; 1; usleep(10000)) {
pid_t wpid = waitpid(g->pid[1], &sig, WNOHANG);
if (wpid > 0) break;
if (wpid < 0) print("wait error: %s\n", strerror(errno));
}
}
waitpid
应该立即返回子进程的pid!
但是 waitpid
在大约 90 秒后得到了 pid 号,
cube 28139 0.0 0.0 70576 900 ? Ss 04:24 0:07 ./daemon -d
cube 28140 9.3 0.0 0 0 ? Zl 04:24 106:19 [daemon] <defunct>
strace -p 28139
Process 28139 attached - interrupt to quit
restart_syscall(<... resuming interrupted call ...>) = 0
wait4(28140, 0x7fff08a2681c, WNOHANG, NULL) = 0
nanosleep({0, 10000000}, NULL) = 0
wait4(28140, 0x7fff08a2681c, WNOHANG, NULL) = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
restart_syscall(<... resuming interrupted call ...>) = 0
wait4(28140, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGKILL}], WNOHANG, NULL) = 28140
最佳答案
我终于发现在 lsof 的深度跟踪过程中存在一些 fd 泄漏。
修复 fd 泄漏后,问题就消失了。
关于Linux、waitpid、WNOHANG、子进程、僵尸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22733364/
程序: #include #include #include #include #include int main() { int pid=fork(); if(pid==0){
我需要能够: fork 一个进程并使它成为 execvp(我做到了) 检查子进程execvp是否成功(不知道如何) 检查子进程是否完成(有问题) 我正在 fork 一个进程,但我没有任何方法来检查 c
我有点懵。据我了解,pid 为 -1 的 waitpid 意味着我等待所有 child 完成但是如果我向 WNOHANG 的 waitpid 添加一个选项,该选项表示如果没有完成则立即退出......
我将我的程序作为守护进程运行。 父进程只等待子进程,当它意外死亡时,fork并再次等待。 for (; 1;) { if (fork() == 0) break; int sig = 0;
在构建 shell 程序时,我遇到了识别进程状态的问题。我面临的问题的描述是,我有一个子进程列表,我正在尝试使用 waitpid 和 WNOHANG 来弄清楚它们的状态。我想区分 3 种状态:TERM
我想知道我的子进程何时退出。但我不想阻止我的应用程序,所以我使用 WNOHANG。 #include #include #include #include #include #include
我需要一个在 C 中组合使用 waitpid、WNOHANG 和 SIGCHLD 的示例,以及如何将它们全部用于 fore\background? signal( SIGCHLD, SIG_IGN
我目前正在上系统编程课,我们今天复习了 wait 系统调用函数。我正在阅读有关 waitpid() 系统调用的部分,并在选项部分列出了一个名为 WNOHANG 的部分。 pid_t waitpid*(
我正在编写一个程序,其中可以创建多个子进程,并且即使子进程尚未终止,父进程也会继续执行。但是,一旦它们终止,我希望在提示用户创建更多子进程之前打印它们。 根据我对(waitpid((pid_t)-1,
摘自Unix Network Programming Vol1 Third Edition Section 5.10 wait and waitpid functions #include "u
我是一名优秀的程序员,十分优秀!