pcntl_wifexited> <pcntl_waitpid
Last updated: Fri, 03 Feb 2012

pcntl_wexitstatus

(PHP 4 >= 4.1.0, PHP 5)

pcntl_wexitstatusReturns 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



User Contributed Notes
pcntl_wexitstatus
imanecr at gmail dot com
30-Jun-2011 02:04
$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_wifexited> <pcntl_waitpid
Last updated: Fri, 03 Feb 2012