in reply to simoultaneous connections using Net::SSH::Perl

Here's some example code with the fork()'s in place:
#! /usr/bin/perl -w use strict; $SIG{CHLD} = \&REAPER; my @server_list = qw/one two three four/; my $children = 0; foreach my $server (@server_list) { print "$$ Forking for server: $server\n"; if (my $pid = fork) { # Parent process # Nothing to do except go to the next server in the list $children++; sleep 2; next; } else { # Child process # Note that you *must* use 'exit;' when processing is # finished or the child will continue going through the # loop print "$$ Processing for server: $server\n"; sleep 3; exit; } } # Wait for children to finish while ($children > 0) { sleep; } sub REAPER { my $pid = wait; print "Process $pid has done it's stuff!\n"; $children--; }
When a forked process dies, the parent process will get a SIGCHLD signal (I am assuming you are using UNIX). Unless the parent does something with this signal, the child process will becoma a 'zombie', and eventually the process table will fill up (not good). If you don't need to keep track of the children as they finish, do $SIG{CHLD} = 'IGNORE'. I've put some delays in the example code so you can see this happening.

You should also be aware that as with any system call, a fork() can fail. Read page 715 of 'Programming Perl, 3rd edition' for more info.

JJ