I realize this is an old post, but since there was not a solution here, I figured I would post mine.

I was having the same issue- Net::Appliance::Session (actually, Net::Appliance::Session::Transport::SSH) spawns a child proc for the ssh session, but even after I do $s->close() AND $s goes out of scope, I still see that child proc running when I do a ps. In my case, the ssh connection did not even succeed. Also, my program redirected SIG DIE to my own handler, which I thought might have been messing up Net::Appliance::Session's own signal handling (though this does not seem to be the case).

Anyway, it turns out that Net::Appliance::Session keeps track of its own children. You can use the method childpid() to get the child's pid. Then, you can check if it is still running and kill it yourself if need be. I have pasted a snippet of my own code below, which seems to work. Note, this only handles the case when the the connection/login fails- you would need some similar code elsewhere in your script to handle the lingering process if you log in successfully and close out the session later.

sub login_ssh { my $ip = shift; my $uname = shift; my $pword = shift; # I remapped the SIG handler for DIE elsewhere in my code. # If the SSH connection fails, it will be caught by # that handler, which I do not want. So remap it temporarily. my $old_sigdie = $SIG{__DIE__}; $SIG{__DIE__} = sub { mylog(MSG_NOTICE, "Caught SIG to DIE: $_[0]. Ignoring"); }; my $conn = Net::Appliance::Session->new( Host => $ip, Transport => 'SSH' ); eval { # eval {} probably not necessary in this particular case, # since we intercept SIG DIE $conn->connect(Name => $uname, Password => $pword); }; # The ssh procs are sticking around even after we fail to log in. # Get the child pid spawned by # Net::Appliance::Session::Transport::SSH so we can kill it explic +itly my $sshpid = $conn->childpid(); if ($conn->logged_in()) { # return an open Net::Appliance::Session session return $conn; } else { if ($@) { process_error($@); } $SIG{__DIE__} = $old_sigdie; $conn->close(); if (kill(0, $sshpid) > 0) { mylog("Child SSH proc $sshpid is still running. Killing i +t"); my $rc = kill TERM => $sshpid; } if (kill(0, $sshpid) > 0) { mylog("Child SSH proc $sshpid is still running. Kill -9'i +ng it"); my $rc = kill 9 => $sshpid; } return; } }

In reply to Re^2: Net::Appliance::Session - using SSH will keep process open by ryber
in thread Net::Appliance::Session - using SSH will keep process open by scottdware

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.