Marketing_Insists
asked on
Forking a processes in perl
How could I launch the below indicated line or any other block of code on all array parameters at once in a nonlinear method? Basically cloning the block 5 times.
I've heard of heard of fork() and the win32::process module, but I can't clearly understand how to implement what I need to do with the samples given: (win32 perl by the way)
@array = qw{ server1 server2 server3 server4 server5 };
for (@array) {
# How can I clone the below line 5 times instead of running sequentially?
push(@out,( `ping -n 120 $_` ));
}
# output results
print @out;
I've heard of heard of fork() and the win32::process module, but I can't clearly understand how to implement what I need to do with the samples given: (win32 perl by the way)
@array = qw{ server1 server2 server3 server4 server5 };
for (@array) {
# How can I clone the below line 5 times instead of running sequentially?
push(@out,( `ping -n 120 $_` ));
}
# output results
print @out;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You might also want to consider the Net::Ping module, using the "syn" protocol. This allows you to ping multiple hosts simultaneously without forking.
http://search.cpan.org/~smpeters/Net-Ping-2.35/lib/Net/Ping.pm
http://search.cpan.org/~smpeters/Net-Ping-2.35/lib/Net/Ping.pm
system "ping -n 120 $_ &" for @array