perl 中的进程管理
来源:互联网 发布:企业大数据运营平台 编辑:程序博客网 时间:2024/04/30 20:37
use POSIX ":sys_wait_h";my $j = 1;for ($j=1;$j<8 ;$j++) { DTM_MP($j);}sub DTM_MP{ my $RX=@_[0]; print "get $RX here\n"; my $i = 0; for ($i=1;$i<=16 ;$i++) { my $child = fork(); if($child) { warn "launching one subprocess\n"; } else { #my $cmd = "echo \"fda\""; #system($cmd); ##write log## $RX.$ITN.$j.log my $logFile = "subProcess.$RX.$i.log"; #print $logFile."\n"; open(WFILE,">$logFile") || die; print WFILE "sub process $RX\_$i finished\n"; close(WFILE); exit 0; } } $i=1; while ($i<=16) { if(!-e "subProcess.$RX.$i.log") { sleep(10); } else { $i++; } } my $index = 1; my $key = 0; for (;$index<=16 ;$index++) { $key = waitpid(-1,WNOHANG); print "GGG:$key\n"; } }