如何检测 Linux 上失效的进程?
我有一个用 C 语言编写的父进程和子进程。在父进程的某个地方,HUP 信号被发送到子进程。我希望我的父进程检测孩子是否死亡。但是当我发送 SIGHUP 时,子进程就变成了僵尸。如何检测子进程是否是父进程中的僵尸?我尝试下面的代码,但它没有返回我想要的结果,因为子进程仍然存在,但它已经失效。
kill(childPID, 0);
还有一个问题;我可以在不杀死父母的情况下杀死僵尸孩子吗?
谢谢。
I have a parent and a child process written in C language. Somewhere in the parent process HUP signal is sent to the child. I want my parent process to detect if the child is dead. But when I send SIGHUP, the child process becomes a zombie. How can I detect if the child is a zombie in the parent process? I try the code below, but it doesn't return me the desired result since the child process is still there but it is defunct.
kill(childPID, 0);
One more question; can I kill the zombie child without killing the parent?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自维基百科:
如果父进程通过调用 wait、waitpid 等获取退出状态,则僵尸应该消失。
您可以通过等待函数(man wait)检测进程是否存活。
from wikipedia:
If the parent fetches the exit status by calling wait, waitpid or the like, the zombie should disappear.
You can detect whether a process is alive through the wait functions (man wait).