我在列表(文件)中有24个任务(unix命令)。他们需要在给定时间执行5。任务完成后,脚本应执行下一个任务,直到执行/竞争所有24个任务。同时在前景中我有一个while循环用" ps"用于监视活动的命令。有什么想法吗?
答案 0 :(得分:3)
use Parallel::ForkManager qw( );
my $pm = Parallel::ForkManager->new(5);
for my $task (@tasks) {
$pm->start() and next;
my $exit_code = 0;
if (!eval {
...
return 1; # No exception
}) {
$exit_code = $! || $? >> 8 || 255;
warn($@);
}
$pm->finish($exit_code);
}
$pm->wait_all_children();
答案 1 :(得分:0)
You can get info from your process monitoring with Proc::ProcessTable
This is an example:
<nearme>
<location id="1">A</location>
<location id="2">B</location>
<location id="3">C</location>
<location id="4">D</location>
<location id="5">E</location>
<location id="6">F</location>
<location id="7">G</location>
<location id="8">H</location>
<location id="9">I</location>
<location id="10">J</location>
<location id="11">K</location>
<location id="12">L</location>
</nearme>
If you´re using Windows, maybe you can use Win32::Process* modules. But I never used!