views:

318

answers:

1

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.

+3  A: 

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

Ronny
Thanks for the tip.
Hakan