Link to home
Start Free TrialLog in
Avatar of Marketing_Insists
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;
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
#if you only care about printing the output
system "ping -n 120 $_ &" for @array
Avatar of Adam314
Adam314

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