note 110790 modified in function.pcntl-fork by danbrown
| From: | danbrown@php.net | Date: | Sat, 08 Dec 2012 16:17:23 +0000 |
| Subject: | note 110790 modified in function.pcntl-fork by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192397@lists.php.net to get a copy of this message | ||
Its been easy to fork process with pcntl_fork.. but how can we control or process further once all
child processes gets completed.. here is the way we can do that...
<?php
for ($i = 1; $i <= 5; ++$i) {
$pid = pcntl_fork();
if (!$pid) {
sleep(1);
print "In child $i\n";
exit($i);
}
}
while (pcntl_waitpid(0, $status) != -1) {
$status = pcntl_wexitstatus($status);
echo "Child $status completed\n";
}
?>
--was--
Its been easy to fork process with pcntl_fork.. but how can we control or process further once all
child processes gets completed.. here is the way we can do that...
for ($i = 1; $i <= 5; ++$i) {
$pid = pcntl_fork();
if (!$pid) {
sleep(1);
print "In child $i\n";
exit($i);
}
}
while (pcntl_waitpid(0, $status) != -1) {
$status = pcntl_wexitstatus($status);
echo "Child $status completed\n";
}
http://php.net/manual/en/function.pcntl-fork.php