ID: 27739
Updated by: [EMAIL PROTECTED]
Reported By: bhook at coder7 dot com
-Status: Closed
+Status: Bogus
Bug Type: *Extensibility Functions
Operating System: Slackware 9.1 (Linux 2.6.4)
PHP Version: 5.0.0RC1
New Comment:
Only real bugs that have been fixed should have status Closed.
Previous Comments:
------------------------------------------------------------------------
[2004-03-27 16:05:22] bhook at coder7 dot com
The child processes will go defunct if the parent doesn't retrieve
their status. Adding:
pcntl_waitpid(-1,$c_status,WNOHANG);
as the last line inside the loop fixes the defunct processes.
------------------------------------------------------------------------
[2004-03-27 15:24:07] bhook at coder7 dot com
Description:
------------
When using pcntl_fork(), if a child script finishes execution (or
exit/dies), the process goes defunct. I've found that with my
particular needs I can reverse the normal programming method used with
a server-like application, and the defunct problem goes away.
For example, if I had a script that waited for a socket connection,
then I would spawn child processes to handle any connections. This
causes defunct processes when the children exit. Instead, I have to
spawn a child that continues listening, and the parent process handles
the current connection. When the parent finishes execution, it exits
cleanly, and the child becomes the new "parent".
Reproduce code:
---------------
for($a=0;$a<=10;$a++)
{
$pid=pcntl_fork();
if($pid==-1){die('fork error');}
elseif($pid==0) //child process
{
echo "hello world\n";
exit;
}
else //parent process
{
/* Continue Looping */
}
}
passthru('ps -a | grep php');
Expected result:
----------------
Expected output of passthru() would be to have 1 properly functioning
process listed.
Actual result:
--------------
Defunct processes are created. These processes will persist until the
parent process dies.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27739&edit=1