文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>perl fork -- how to controlls process numbers

perl fork -- how to controlls process numbers

时间:2010-04-22  来源:icilallenzhang

#!/usr/bin/perl -w
use POSIX ":sys_wait_h"; our $num = 3000; our $fnum = 0; our @childs;
$SIG{CHLD} = \&REAPER;
#if parent get CHLD exit signal, we do $fnum--,  #so while loop will fork another child sub REAPER {         $fnum--;         #$fnum = 0;         print "fnum--\n";         my $pid;  while (($pid = waitpid(-1, WNOHANG)) > 0) {
                print "$pid die\n";         }
}
while($num>0){     if($fnum<1000){         my $pid = fork();         if($pid ==0 ){                 #child                 sleep(int(rand(5)));                 #sleep(1);                 print "this is a child $num\n";                 exit(0);         }         else{                 push(@childs,$pid);                 print "fnum++\n";                 $fnum++;                 $num--;                 print "fork child $pid\n";                 print "fnum is $fnum\n";         }      } }
foreach(@childs){         waitpid($_,0);         $fnum=0; }
相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载