<?php
date_default_timezone_set( 'Asia/Beijing'); echo "parent start, pid ", getmypid(), "\n" ; beep(); echo "\n\n"; $a = 1; for ($i=0; $i<10; ++$i){ $pid = pcntl_fork(); if ($pid == -1){ die ("cannot fork" ); } else if ($pid > 0){ echo "父进程 $i ".getmypid()."\n"; echo $pid."\n"; } else if ($pid == 0){ echo "子进程 start, pid ", getmypid(), "\n" ; for ($j=0; $j<1; ++$j){ beep(); } echo $a."\n"; exit ; } } // *** function beep(){ echo getmypid(), "\t" , date( 'Y-m-d H:i:s', time()), "\n" ; //sleep(1); }
?>