So, I have this PHP daemon worker that listens to IPC messages. Weird thing is that the parent process (result from pcntl_fork) leaves a [php] < defunct> process untill the child process is done but ONLY when the script is started form a cronjob, not directly from command line.
I know < defunct> processes aren't evil, but I can't figure out why it's happening only when running from a cronjob.
Command
/path/to/php/binary/php /path/to/php/file/IpcServer.php
Forking code:
$iParent = posix_getpid();
$iChild = pcntl_fork();
if ($iChild == -1)
throw new Exception("Unable to fork into child process.");
elseif ($iChild)
{
echo "Forking into background [{$iChild}].\n";
Log::d('Killing parent process (' . $iParent. ').');
exit;
}
Output
Forking into background [20835].
Killing parent process (20834).
ps aux | grep php
root 20834 0.0 0.0 0 0 ? Zs 14:28 0:00 [php] <defunct>
root 20835 0.0 0.2 275620 8064 ? Ss 15:35 0:00 /path/to/php/binary/php /path/to/php/file/IpcServer.php
I've found out that it's a known apache bug, but then why do I get this bug when running from cronjob?