【发布时间】:2016-08-05 21:29:57
【问题描述】:
我正在编写的一段代码使用Parallel::ForkManager,我注意到它在脚本运行时创建了许多僵尸。我想知道在wait_all_children 方面我是否遗漏了什么。
my $fork_manager = new Parallel::ForkManager->($ENV{CPUS})
for(my $i = 0; $i < scalar @plates; $i++){
my $offset = get_full_plate_offsets(@{$plates[$i]});
make_path(File::Spec->catfile($tmp_dir, $i));
foreach my $cell (keys %{$offset}){
my($x, $y) = @{$offset->{$cell}};
$fork_manager->start("$cell @ $x, $y") and next;
my $out_file = File::Spec->catfile($tmp_dir, $i, "$cell.jpg");
my $out_text = File::Spec->catfile($tmp_dir, $i, "$cell.txt");
split_file($input_jpg, [$x, $y], $out_file);
my $result = do_something($out_file);
open(my $FH, '>', $out_text);
print $FH "$result\n";
$fork_manager->finish;
}
$fork_manager->wait_all_children;
}
也是一个澄清问题。僵尸总是坏的对吧?
起初我的印象是僵尸进程只是尚未被其父进程恢复的进程。现在我想知道我的代码是否根本没有在等待孩子们。
【问题讨论】:
标签: perl fork zombie-process