代码
$ipid)
{
$res = pcntl_waitpid($ipid, $status, wnohang);
if($res == -1 || $res > 0)
{
unset($archildid[$ikey]);
echo '* sub process: '. $ipid. ' exited with '. $status. php_eol;
}
}
}
# 子进程执行的逻辑
function excuteprocess($ipid, $iseconds)
{
file_put_contents('./log/'.$ipid.'.log', $ipid.php_eol, file_append);
sleep($iseconds);
}
?>
运行结果
* process 16163 was created, and executed, and sleep 11
* process 16164 was created, and executed, and sleep 21
* process 16165 was created, and executed, and sleep 24
* process 16166 was created, and executed, and sleep 27
* process 16167 was created, and executed, and sleep 8
* process 16168 was created, and executed, and sleep 14
* process 16169 was created, and executed, and sleep 14
* process 16170 was created, and executed, and sleep 26
* process 16171 was created, and executed, and sleep 20
* process 16172 was created, and executed, and sleep 21
* sub process: 16167 exited with 0
* sub process: 16163 exited with 0
* sub process: 16169 exited with 0
* sub process: 16168 exited with 0
* sub process: 16171 exited with 0
* sub process: 16164 exited with 0
* sub process: 16172 exited with 0
* sub process: 16165 exited with 0
* sub process: 16170 exited with 0
* sub process: 16166 exited with 0