note 31812 added to function.pcntl-fork

From: Date: Mon, 05 May 2003 01:10:28 +0000
Subject: note 31812 added to function.pcntl-fork
Groups: php.notes 
Request: Send a blank email to php-notes+get-47523@lists.php.net to get a copy of this message
To help alleviate a lot of confusion for people just starting working with forking in PHP and why they keep getting zombie processes.. Each child process in unix systems will, upon exit, send a status message to their parent, if no parent then the status message just sits and the child hangs out for a wait() from their parent. Here is a rewite of the example provided above in the main docs to show how to wait on a child process so it won't zombie. <?php $pid = pcntl_fork(); if ($pid == -1) { die("could not fork"); } else if ($pid) { // we are the parent pcntl_waitpid(-1,$status); // this waits on the child **** } else { // we are the child // code block for child process to run } ?> This was a cause of some greif for me until I started reading some c books on processes. I had zombies all over.. Hope that helps. -- http://www.php.net/manual/en/function.pcntl-fork.php http://master.php.net/manage/user-notes.php?action=edit+31812 http://master.php.net/manage/user-notes.php?action=delete+31812 http://master.php.net/manage/user-notes.php?action=reject+31812

« previous php.notes (#47523) next »