Home > Backend Development > PHP Tutorial > The pcntl_wait function fails to suspend the parent class process

The pcntl_wait function fails to suspend the parent class process

WBOY
Release: 2016-09-21 14:13:14
Original
1235 people have browsed it

Why won’t the parent process be suspended when

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>
Copy after login
Copy after login
<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>
Copy after login
Copy after login
NULL

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

int(26003)

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

int(26003)

iiiiiii

Reply content:

Why won’t the parent process be suspended when

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>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

NULL

I'm child26003

ccpint(26004)
bool(true)
bool(false)
bool(false)
int(0)
int(0)
pppppppppp

int(26003)

iiiiiii hangs

string(8) "main 26003"
int(26004)
I'm child26003
ccpint(26005)
bool(true)
bool(false)
bool(false)
int (0)
int(0)
ppppppppp

int(26003)

iiiiiii

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template