1
我想並行運行一個Perl腳本,並在這裏卡住了一個點。查看示例腳本:perl Parallel :: ForkManager卡在這個腳本中?
如果我沒有-fork 4
選項來運行它,它運行良好:
perl perl_parallel_forkmanager_ls.pl -limit 10
799c89a4c78eafbfb9e7962b8e9705f7 /etc/apt/trusted.gpg
ff163e8e9e38670705a9f2cea8b530c9 /etc/apt/trusted.gpg~
075e92fd5c6f0dcdad857603f03dd3a5 /etc/bash_completion.d/R
b269c1383a87a7da2cc309c929ba35ca /etc/bash_completion.d/grub
7cbefff45508d2ed69576bebc80e66bb /etc/bash_completion.d/docker
facb1fdc0fcf7f6b150442d1a9036795 /etc/bash_completion.d/pulseaudio-bash-completion.sh
69dfca7a7b55181cef06b9ed28debb20 /etc/gnome/defaults.list
a65e81e55558941ce0f3080b9333e18f /etc/sensors3.conf
9e87bc86a77261acfb2bae618073a787 /etc/grub.d/20_linux_xen
8039709ee9648dabda0cdca713f2ed49 /etc/grub.d/30_os-prober
1bc18861cc2438517ce6b6c22fd4fa49 /etc/grub.d/10_linux
但是,如果我的-fork 4
比-limit 10
值小的值運行它,它忽略了價值的限制:
perl perl_parallel_forkmanager_ls.pl -fork 4 -limit 10 2>/dev/null | wc -l
80
任何想法?
#!/usr/bin/perl
use strict;
use warnings;
use Parallel::ForkManager;
use Getopt::Long;
my $dir = '/etc'; my $fork = 1; my $size = '9876'; my $limit;
my $verbose;
GetOptions(
'dir:s' => \$dir,
'fork:s' => \$fork,
'size:s' => \$size,
'limit:s' => \$limit,
'verbose' => \$verbose,
);
my $cmd; my $ret;
$cmd = "find $dir -size +".$size."c -type f 2>/dev/null";
open(P, "-|", "$cmd") or die "$cmd -- $!";
my $pm; $pm=new Parallel::ForkManager($fork) if ($fork > 1);
my $count = 0;
while (<P>) {
if ($fork > 1) {
$pm->start and next;
}
my $file = $_; chomp $file;
my $md5 = `md5sum $file`;
print "$md5";
$pm->finish if ($fork > 1);
$count++;
last if (defined $limit && $count > $limit);
};
$pm->wait_all_children if ($fork > 1);
close P;