|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27739 pcntl_fork() children go <defunct> on completion
Submitted: 2004-03-27 15:24 UTC Modified: 2004-03-28 02:08 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bhook at coder7 dot com Assigned:
Status: Not a bug Package: *Extensibility Functions
PHP Version: 5.0.0RC1 OS: Slackware 9.1 (Linux 2.6.4)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
46 - 4 = ?
Subscribe to this entry?

 [2004-03-27 15:24 UTC] bhook at coder7 dot com
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:
  if($pid==-1){die('fork error');}
  elseif($pid==0) //child process
    echo "hello world\n";
  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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-27 16:05 UTC] bhook at coder7 dot com
The child processes will go defunct if the parent doesn't retrieve their status. Adding:


as the last line inside the loop fixes the defunct processes.
 [2004-03-28 02:08 UTC]
Only real bugs that have been fixed should have status Closed.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 06:03:33 2021 UTC