note 104677 deleted from function.pcntl-wexitstatus by danbrown
| From: | danbrown@php.net | Date: | Thu, 30 Jun 2011 13:44:15 +0000 |
| Subject: | note 104677 deleted from function.pcntl-wexitstatus by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181104@lists.php.net to get a copy of this message | ||
Note Submitter: imanecr at gmail dot com
----
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} else if ($pid) {
// we are the parent
$myId = pcntl_waitpid(-1, $status, 0);
$children_ret = pcntl_wexitstatus($status);
echo "return code " . $children_ret;
return 0;
} else {
// we are the child
return 2;
}
output: return code 0
you should use exit not return
like this
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} else if ($pid) {
// we are the parent
$myId = pcntl_waitpid(-1, $status, 0);
$children_ret = pcntl_wexitstatus($status);
echo "return code " . $children_ret;
return 0;
} else {
// we are the child
exit(2);
}
output: return code 2