note 115714 added to function.pcntl-waitpid
| From: | fx4084 at gmail dot com | Date: | Fri, 12 Sep 2014 07:53:12 +0000 |
| Subject: | note 115714 added to function.pcntl-waitpid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200425@lists.php.net to get a copy of this message | ||
<?php
$childs = array();
// Fork some process.
for($i = 0; $i < 10; $i++) {
$pid = pcntl_fork();
if($pid == -1)
die('Could not fork');
if ($pid) {
echo "parent \n";
$childs[] = $pid;
} else {
// Sleep $i+1 (s). The child process can get this parameters($i).
sleep($i+1);
// The child process needed to end the loop.
exit();
}
}
while(count($childs) > 0) {
foreach($childs as $key => $pid) {
$res = pcntl_waitpid($pid, $status, WNOHANG);
// If the process has already exited
if($res == -1 || $res > 0)
unset($childs[$key]);
}
sleep(1);
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 202.108.16.78
----
Manual Page -- http://php.net/manual/en/function.pcntl-waitpid.php
Edit -- https://master.php.net/note/edit/115714
Del: integrated -- https://master.php.net/note/delete/115714/integrated
Del: useless -- https://master.php.net/note/delete/115714/useless
Del: bad code -- https://master.php.net/note/delete/115714/bad+code
Del: spam -- https://master.php.net/note/delete/115714/spam
Del: non-english -- https://master.php.net/note/delete/115714/non-english
Del: in docs -- https://master.php.net/note/delete/115714/in+docs
Del: other reasons-- https://master.php.net/note/delete/115714
Reject -- https://master.php.net/note/reject/115714
Search -- https://master.php.net/manage/user-notes.php