From: bhook at coder7 dot com
Operating system: Slackware 9.1 (Linux 2.6.4)
PHP version: 5.0.0RC1
PHP Bug Type: *Extensibility Functions
Bug description: pcntl_fork() children go <defunct> on completion
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 bug report at http://bugs.php.net/?id=27739&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27739&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27739&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27739&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27739&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27739&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27739&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27739&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27739&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27739&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27739&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27739&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27739&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27739&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27739&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27739&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27739&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27739&r=float