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


In reply to Re^2: Parallel::Forkmanager question by jamesgerard1964
in thread Parallel::Forkmanager question by jamesgerard1964

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.