Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

This question has a lot of non-Perl parts to it, but I'm running a Perl script on a remote machine, so it would be nice to solve the problem in Perl.

I'm trying to start a detached process on a remote server. The following test shows my problem:

ssh user@host 'perl-E "fork or exec q{sleep 20}"'
or equivalently:
ssh user@host 'perl-E "$|++; \$SIG{CHLD}=q{IGNORE}; say q{START}; if( +fork){exit}else{close STDIN; close STDOUT; close STDERR; exec q{sleep + 20}}"'

If the remote machine is linux, the first version waits for 20 seconds, and the second version exits immediately. But most of my machines are windows machines running cygwin opensshd, and the connection stays open until the child is finished in both versions. I can't do the detach on my side of the connection because I need to conserve network ports.

One option has been to use sysinternals psexec -d to launch the detached process, but this frequently fails silently, particularly shortly after booting the machine. It does at least close the ssh connection immediately. Since I'm running a Perl script on the remote machine anyway, it would make sense to do this completely in Perl. My ssh calls are actually made via Net::OpenSSH, but the test shows that this is not causing the problem.

(I tried posting this on G+ yesterday to see if the perl "community" there could help: https://plus.google.com/#communities/105035827361077606043. So far nothing )





- Boldra

In reply to cygwin opensshd: how to detach remotely with fork/exec? by Boldra

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (9)
    As of 2014-07-29 10:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (213 votes), past polls