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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.