Rumah  >  Artikel  >  pembangunan bahagian belakang  >  pcntl_wait函数挂起父类进程失败

pcntl_wait函数挂起父类进程失败

WBOY
WBOYasal
2016-09-21 14:13:141214semak imbas

sum =2 时为什么不会挂起父进程呢

$sum = 0;

<code>    while(true){
        $sum++;
        $pid= pcntl_fork();

        switch($pid){

            case "-1":

                echo"couldn't fork";

                break;
            case "0":{

                var_dump(getmypid());
                var_dump(pcntl_wifexited($status), pcntl_wifstopped($status), pcntl_wifsignaled($status), pcntl_wexitstatus($status), pcntl_wtermsig($status));
                echo 'ppppppppp';
</code>
<code>                exit(0);
            }

            default: {
                if($sum == 2){

                   // $subPid = pcntl_waitpid(-1, $status, SI_ASYNCIO);
                   $subPid = pcntl_wait($status);
                    echo '挂起'."\n";
                }

                var_dump('主'.getmypid());
                var_dump($subPid);
                echo "I'm child" . getmypid() . "\n";
                echo 'ccp';
                //就会执行子进程
                sleep(30);
                echo "\n\n\n";
            }

              //  exit(0);

        }
        var_dump(getmypid());
        echo 'iiiiiii';
        if($sum == 2)
        break;

    }
    
    
    这个是答案 
                    string(8) "主26003"</code>

NULL
I'm child26003
ccpint(26004)
bool(true)
bool(false)
bool(false)
int(0)
int(0)
ppppppppp

int(26003)
iiiiiii挂起
string(8) "主26003"
int(26004)
I'm child26003
ccpint(26005)
bool(true)
bool(false)
bool(false)
int(0)
int(0)
ppppppppp

int(26003)
iiiiiii

回复内容:

sum =2 时为什么不会挂起父进程呢

$sum = 0;

<code>    while(true){
        $sum++;
        $pid= pcntl_fork();

        switch($pid){

            case "-1":

                echo"couldn't fork";

                break;
            case "0":{

                var_dump(getmypid());
                var_dump(pcntl_wifexited($status), pcntl_wifstopped($status), pcntl_wifsignaled($status), pcntl_wexitstatus($status), pcntl_wtermsig($status));
                echo 'ppppppppp';
</code>
<code>                exit(0);
            }

            default: {
                if($sum == 2){

                   // $subPid = pcntl_waitpid(-1, $status, SI_ASYNCIO);
                   $subPid = pcntl_wait($status);
                    echo '挂起'."\n";
                }

                var_dump('主'.getmypid());
                var_dump($subPid);
                echo "I'm child" . getmypid() . "\n";
                echo 'ccp';
                //就会执行子进程
                sleep(30);
                echo "\n\n\n";
            }

              //  exit(0);

        }
        var_dump(getmypid());
        echo 'iiiiiii';
        if($sum == 2)
        break;

    }
    
    
    这个是答案 
                    string(8) "主26003"</code>

NULL
I'm child26003
ccpint(26004)
bool(true)
bool(false)
bool(false)
int(0)
int(0)
ppppppppp

int(26003)
iiiiiii挂起
string(8) "主26003"
int(26004)
I'm child26003
ccpint(26005)
bool(true)
bool(false)
bool(false)
int(0)
int(0)
ppppppppp

int(26003)
iiiiiii

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn