Hello jamesgerard1964,
Give the following a try. Please excuse me for filling in the missing pieces. Thus, adjust accordingly to suit your task.
use strict; use warnings; use Parallel::ForkManager; my @servers = ('a'..'z'); my $timeout = 10; my $user = "foo"; my $file = "/tmp/hello.txt"; my $rpath = "/tmp"; my $fname = "hello.txt"; my $fork_manager = Parallel::ForkManager->new(8); $fork_manager->set_waitpid_blocking_sleep(0); foreach my $server (@servers) { my $pid = $fork_manager->start; if ($pid) { # parent print "$$: child process started, with a key of $server ($pid)\n"; } else { # child eval { local $SIG{ALRM} = sub { alarm 0; die "alarm\n" }; alarm $timeout; my $rc = system("scp -p $file $user\@$server:$rpath/$fname"); }; alarm 0; $fork_manager->finish; } } $fork_manager->wait_all_children();
A non-zero $pid values is meant for the parent process. Therefore, a $pid value when 0 is the child process itself.
In reply to Re: Parallel::Forkmanager question
by Anonymous Monk
in thread Parallel::Forkmanager question
by jamesgerard1964
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |