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?
In reply to Net::OpenSSH and fork() by scotchie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |