开发者

How to detect defunct processes on Linux?

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 开发者_C百科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.


from wikipedia:

On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the process that started the (now zombie) process to read its exit status.

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜