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