두 가지 방법으로 확인했지만 성공하지 못한 것 같습니다.두 개 이상의 Perl 프로그램을 병렬로 실행하는 방법 - 두 개 이상의 .pl 파일 사용
두 펄 파일 Parallel::ForkManager
pro_1.pl
use strict;
for (1..10) {
print "finite for one\n";
}
pro_2.pl
use strict;
for (1..10){
print "finite for two\n";
}
사례 1, 아래의 경우에 사용되는,
use strict;
use warnings;
use Parallel::ForkManager;
my $pm = new Parallel::ForkManager(2);
my @all_pro = ("pro_1.pl", "pro_2.pl");
foreach my $pro (@all_pro) {
# Forks and returns the pid for the child:
my $pid = $pm->start and next;
system ("perl $pro");
$pm->finish; # Terminates the child process
}
출력 : 두 개의 서로 다른 프로그램에서 인쇄 문 사이에 인터리브가 없습니다
$ finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
. 두 경우 모두에 대한
$ finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for one
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
finite for two
출력은 동일 : 펄을 사용하여
사례 2는
use threads;
my $child_thread = threads->new(\&my_function1, "pro_1.pl");
my $child_thread2 = threads->new(\&my_function2, "pro_2.pl");
# ...
my $this_thread = threads->self;
print "Main thread: $this_thread\n";
my $tid = $this_thread->tid;
print "TID of current thread: $tid\n";
my @threads = threads->list;
print "All threads: @threads\n";
foreach my $thr (@threads) {
my $thr_pid = $thr->tid;
print "Child Thread PID: $thr_pid\n";
$thr->join;
}
sub my_function1 {
system ("perl @_");
}
sub my_function2 {
system ("perl @_");
}
출력 스레드. 이 경우 실제로 첫 번째 프로그램이 완료되면 두 번째 프로그램이 실행됩니다. 진정한 병렬 처리가 아닙니다. 서브 루틴에서 실행하면 병렬 처리가 수행됩니다. 즉, "2에 대해 유한"문과 "1에 대해 유한"문이 인터리브 된 것을 볼 수 있습니다.
많은 핵심 엔진 인 MCE를 살펴보십시오. CPAN 모듈. –