php forking issue

前端 未结 2 879
春和景丽
春和景丽 2021-01-28 15:34

I have the following test php to do a fork/spawn process, where the test also attempts to kill the child process (zombie) after is completes..

I\'d like to have a more e

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-28 16:29

    Fork in foreach:

    0) {}'));//protect against zombie children
    foreach ($tasks as $v)
            {if (($pid=pcntl_fork())===-1)
                {//...
                 continue;
                }
             else if ($pid===0)
                  {ob_start();//prevent output to main process
                   register_shutdown_function(create_function('$pars', 'ob_end_clean();posix_kill(posix_getppid(), SIGUSR1);posix_kill(getmypid(), SIGKILL);'), array());//to kill self before exit();, or else the resource shared with parent will be closed
                   //...
                   exit();//avoid foreach loop in child process
                  }
            }
    ?>
    

提交回复
热议问题