Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php pcntl_wifexited始终返回true_Php_Multiprocessing_Pcntl - Fatal编程技术网

Php pcntl_wifexited始终返回true

Php pcntl_wifexited始终返回true,php,multiprocessing,pcntl,Php,Multiprocessing,Pcntl,子进程可能会出错退出,但pcntl_wifexited始终返回true <?php //Sample code : $child_pid = pcntl_fork(); if ($child_pid === 0) { //This is child process $my_var = rand(1,5); if($my_var == 2) { //2 is not allowed exit(1); //exit wi

子进程可能会出错退出,但pcntl_wifexited始终返回true

<?php

//Sample code :
$child_pid = pcntl_fork();

if ($child_pid === 0) 
{
    //This is child process

    $my_var = rand(1,5);

    if($my_var == 2)
    {
        //2 is not allowed
        exit(1); //exit with error
    }

    if($my_var == 4)
    {
        //4 is unknown
        i_crash_now(); //crash
    }

    echo 'end of child' . "\n";
    exit(0); //exit standard

}
else
{
    sleep(1); //waiting for child with ninja code (don't do that at home, this was made by professional ninjas)
    pcntl_waitpid($child_pid, $status, WNOHANG);

    var_dump(pcntl_wstopsig($status));  //in case 2 > 1, in case 4 > 255, else 0
    var_dump(pcntl_wifexited($status)); //always true;
}

exit(0);

我想象pcntl\U waitpid的行为类似于正常的waitpid调用

如果没有进程终止,WNOHANG强制waitpid返回0[这类似于零超时]


因此,退出代码看起来是正常的

我想象pcntl_waitpid的行为与普通waitpid调用类似

如果没有进程终止,WNOHANG强制waitpid返回0[这类似于零超时]


因此,退出代码看起来是正常的

如果子状态代码表示正常退出,则返回TRUE,否则返回FALSE。如果子状态代码表示正常退出,则返回TRUE,否则返回FALSE。我认为这是正确的。所以对于
WNOHANG
我应该使用
pcntl\u wstopsig($status)
。我想这是对的。因此,对于
WNOHANG
我应该使用
pcntl\u wstopsig($status)