scotchie has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone please help with the following question?
Net::OpenSSH creates a named socket for each connection, and I've noticed that it conveniently removes the named socket when the parent process dies.
I'm trying to use Net::OpenSSH and fork() in combination to perform the same operations on multiple target servers, in parallel. For example,
# Open connections for my $server (@targets) { $ssh{$server} = new Net::OpenSSH($server, ...); } # Do stuff in parallel for my $server (@targets) { my $pid = fork(); if ($pid) { $pid{$server} = $pid; } else { # In child process. Do stuff $ssh{$server}->system( stuff ); ... exit 0; } } waitpid($pid{$_}) for @targets; # Do more stuff ... for my $server (@targets) { $ssh->system (more stuff); }
The problem I'm encoountering is that whenever any of the children exit, Net::OpenSSH seems to be removing all of the named sockets. Essentially, it disconnects all connections that were opened in the parent process. I can work around the problem be reconnecting after the waitpid's, but reconnecting takes additional runtime.
Is there any way I can tell Net::OpenSSH not to clean up the named sockets when the child processes exit, but only when the parent exits?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::OpenSSH and fork()
by sflitman (Hermit) on Jul 23, 2010 at 04:14 UTC | |
|
Re: Net::OpenSSH and fork()
by Proclus (Beadle) on Jul 23, 2010 at 06:49 UTC | |
|
Re: Net::OpenSSH and fork()
by salva (Canon) on Jul 23, 2010 at 09:34 UTC | |
by scotchie (Novice) on Aug 03, 2010 at 18:55 UTC | |
by salva (Canon) on Aug 07, 2010 at 08:07 UTC | |
by scotchie (Novice) on Aug 17, 2010 at 17:16 UTC |