4

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.

Community
  • 1
  • 1
Laoneo
  • 1,546
  • 1
  • 18
  • 25

2 Answers2

7

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

  • 2
    Just to add, the reason zombie processes exist at all is so that parent processes can collect their exit status. If the parent never checks, they stick around until the parent exits. – FatalError Jun 14 '13 at 14:17
  • So I assume if the parent doesn't care about the exit status it is safe to kill this processes. – Laoneo Jun 14 '13 at 14:40
  • The parent process, yes. The child processes themselves can not be killed without the parent process being killed because they're already dead processes (hence them being defunct). –  Jun 14 '13 at 14:47
1

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 !

kapad
  • 52
  • 7