How to remove Zombie Process ID?

Hi All!

Each of my applications will terminate if receive pulse code disconect or pulse code coid death by calling exit(0) funtion. Unfortunately they terminate unproperly by leaving Zombie process. How can we remove zombie process? or avoid them?


The zombie state is used to maintain information about the childs for the parent.

To clean the zombie state you need to use wait or waitpid functions in the parent process.

What I use to do, is to use a signal handler to catch the SIGCHLD signal given by the childs to the parent when the child deads.

Inside the main function/loop in the parent process, set the signal handler:

signal(SIGCHLD, F_SIGCHLD_Handler);

Then, the signal handler function (also in the parent process):

void F_SIGCHLD_Handler(int sign)
pid_t pid_child; //Child PID
int status; //Child exit status

while ( (pid_child = waitpid(-1, &status, WNOHANG)) > 0);


I hope it helps. If any doubt, look inside the wait or waitpid functions.

Thanks a lot to drodriqueza. I use signal handler with wait and timer unblock. Thanks again.