标签:style blog http color io ar strong for sp
$pids = array(); $child_pid = pcntl_fork(); if ($child_pid == -1) { throw new Exception( __METHOD__ . "|" . __LINE__ . ": fork() error"); } else if ($child_pid) { //parent exit(0); } else { //child for($i=0;$i<3;$i++) { $child_pid = pcntl_fork(); if($child_pid) { //parent $pids[] = $child_pid; sleep(5); print_r($pids);echo "\n"; }else{ //child break; } } } while(1) { //your code sleep(1); }
理解:每执行一个fork,相当于把代码复制了两分,分别去分析代码的执行情况
for循环中进程fork参考 http://blog.csdn.net/jason314/article/details/5640969
标签:style blog http color io ar strong for sp
原文地址:http://www.cnblogs.com/siqi/p/3996354.html