downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

pcntl_wifexited> <pcntl_waitpid
[edit] Last updated: Fri, 11 May 2012

view this page in

pcntl_wexitstatus

(PHP 4 >= 4.1.0, PHP 5)

pcntl_wexitstatusReturns the return code of a terminated child

Description

int pcntl_wexitstatus ( int $status )

Returns the return code of a terminated child. This function is only useful if pcntl_wifexited() returned TRUE.

Parameters

status

The status parameter is the status parameter supplied to a successful call to pcntl_waitpid().

Return Values

Returns the return code, as an integer.

See Also



add a note add a note User Contributed Notes pcntl_wexitstatus
imanecr at gmail dot com 30-Jun-2011 02:34
$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

 
show source | credits | sitemap | contact | advertising | mirror sites