in reply to Re: Parallel::Forkmanager question
in thread Parallel::Forkmanager question
platform is Linux Red Hat. I am currently testing with 9 servers in the list. When I run the script without Parallel::Forkmanager what is happening is that the script will loop thru and process each server using the system call to scp a file. The script will wait for that system call to finish and then continue to the next server. It seems like that is exactly whats happening with the fork. It's processing 1 server at a time, unless I'm not seeing this correctly. The reason I had the wait for all children is that I want to make sure all the servers have been processed before continuing on. I am adding time stamps to the print statements to show what is happening. Here is the code and the output.
my $concurrent_fork_limit = 9; my $fork_manager = Parallel::ForkManager->new($concurrent_fork_limit); foreach my $server (@servers) { my $pid = $fork_manager->start; if ($pid) { my ($dstamp, $hstamp) = &next_time(); print "$dstamp $hstamp $$: child process started, with a key of $s +erver ($pid)\n"; print "\nWorking On Server -> $server\n"; print "Sending File -> $file\n"; my $timeout = 20; eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; my $rc = system("scp -p $file $user\@$fqdn:$rpath/$fname"); print "\nReturn Code For Server -> $server File -> $file = $r +c\n\n\n"; alarm 0; }; if( $@ ) { $nogood{$server}++; } } $fork_manager->finish; } $fork_manager->wait_all_children(); my ($fstamp, $dstamp, $hstamp) = &next_time(); print "\n\n\n$dstamp $hstamp All Children Finished, Continuing\n\n";
04/06/2017 08:56:23 127266: child process started, with a key of server01 (127269)
Working On Server -> server01.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server01.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:25 127266: child process started, with a key of server02 (127273)
Working On Server -> server02.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server02.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:26 127266: child process started, with a key of server03 (127278)
Working On Server -> server03.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server03.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:28 127266: child process started, with a key of server04 (127282)
Working On Server -> server04.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server04.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:29 127266: child process started, with a key of server05 (127286)
Working On Server -> server05.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server05.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:31 127266: child process started, with a key of server06 (127290)
Working On Server -> server06.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server06.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:32 127266: child process started, with a key of server07 (127294)
Working On Server -> server07.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server07.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:34 127266: child process started, with a key of server08 (127298)
Working On Server -> server08.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server08.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:35 127266: child process started, with a key of server09 (127303)
Working On Server -> server09.domain.com
Sending File -> mkdir.pl
Return Code For Server -> server09.domain.com File -> mkdir.pl = 0
04/06/2017 08:56:35 All Children Finished, Continuing
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parallel::Forkmanager question
by 1nickt (Canon) on Apr 06, 2017 at 13:49 UTC | |
by jamesgerard1964 (Novice) on Apr 06, 2017 at 21:28 UTC | |
by jamesgerard1964 (Novice) on Apr 06, 2017 at 21:43 UTC |