dongzhoulong1797 2009-09-28 18:05
浏览 295
已采纳

为什么我的父进程不等待其子进程执行?

I have the most basic script:

$pid = pcntl_fork();
if ($pid == -1) {
     die('could not fork');
} else if ($pid) {
     // we are the parent
     echo "parent done";
     pcntl_wait($status); //Protect against Zombie children
     echo "all done";
} else {
     // we are the child
     echo "Child finished";
}

When I run this, the output is always "Child finished". I'm running this on a lighttpd server.

  • 写回答

1条回答 默认 最新

  • dsgdg54ef4365 2009-09-28 18:10
    关注

    Could be that your getting a signal from the child but it's not the exit status try some thing like:

    do {
        pcntl_wait($status);
    } while (!pcntl_wifexited($status));
    

    To make sure the status is the exit one (SIGCHILD).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?