Home > Backend Development > PHP Tutorial > PHP多进程的父进程怎么不做事呢? 求问:

PHP多进程的父进程怎么不做事呢? 求问:

WBOY
Release: 2016-06-23 13:21:35
Original
1009 people have browsed it

$arr=array();for($i=0;$i<10;$i++){    $pid = pcntl_fork();    if ($pid == -1) {        die('could not fork');    } else if (!$pid) {        //父进程: 为什么不做事?!        $arr[]=1;        pcntl_wait($status); //等待子进程中断,防止子进程成为僵尸进程。    } else {        $arr[]=mt_rand();    }}
Copy after login


上面的案例,为什么      $arr[]=1, 并没有添加到数组中  . 父进程难道不做事?


回复讨论(解决方案)

$pid = pcntl_fork();
在正常情况下,$pid 应是什么值?

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