$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
pcntl_wexitstatus
(PHP 4 >= 4.1.0, PHP 5)
pcntl_wexitstatus — Returns the return code of a terminated child
Descrição
int pcntl_wexitstatus
( int $status
)
Returns the return code of a terminated child. This function is only useful if pcntl_wifexited() returned TRUE.
Parâmetros
- status
-
O parâmetro status é o parâmetro de status fornecido para uma chamada com sucesso a pcntl_waitpid().
Valor Retornado
Returns the return code, as an integer.
Veja Também
- pcntl_waitpid() - Waits on or returns the status of a forked child
- pcntl_wifexited() - Checks if status code represents a normal exit
User Contributed Notes
pcntl_wexitstatus
pcntl_wexitstatus
imanecr at gmail dot com
30-Jun-2011 02:04
30-Jun-2011 02:04

pcntl_waitpid