note 31812 deleted from function.pcntl-fork by derek

From: Date: Sat, 22 Jan 2005 00:27:48 +0000
Subject: note 31812 deleted from function.pcntl-fork by derek
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-83761@lists.php.net to get a copy of this message
Note Submitter: joeldg at listbid.com Reason: integrated ---- 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.

« previous php.notes (#83761) next »