After doing some research, it appears you'll have to kill the parent process for these defunct child processes to go away.
The most pertinent quote from the link says "You cannot kill a defunct process (a.k.a zombie) as it is already dead."
Pregunta
I made a PHP script which reads some data and starts a new process with pctnl_fork to do some work with the data. When the child processes are finished they stay in as process. ps aux shows me a list of processes like
demo 32229 0.0 0.0 0 0 pts/0 Z 12:23 0:00 [php] <defunct>
demo 32251 0.0 0.0 0 0 pts/0 Z 11:50 0:00 [php] <defunct>
demo 32284 0.0 0.0 0 0 pts/0 Z 11:50 0:00 [php] <defunct>
demo 32298 0.0 0.0 0 0 pts/0 Z 12:56 0:00 [php] <defunct>
demo 32303 0.0 0.0 0 0 pts/0 Z 11:50 0:00 [php] <defunct>
demo 32316 0.0 0.0 0 0 pts/0 Z 12:23 0:00 [php] <defunct>
Can I safely kill this processes as the parent process is still creating new processes to do some work? I know I should probably start the command piping to stderr (according to this topic Insane crond behavior. keeps making defunct bash processes now it is too late. The parent process is running in the background.
Solución
After doing some research, it appears you'll have to kill the parent process for these defunct child processes to go away.
The most pertinent quote from the link says "You cannot kill a defunct process (a.k.a zombie) as it is already dead."
Otros consejos
So as U said, a command in your PHP, like
$a;
pcntl_waitpid($child_pid, $a, WNOHANG|WUNTRACED);
will do the job. to me works, just fine !