Annoying, Remote command does not quit when ssh does

From: Graham Wharton (graham@gwsoft.co.uk)
Date: 04/25/03


From: "Graham Wharton" <graham@gwsoft.co.uk>
Date: Fri, 25 Apr 2003 01:11:03 +0100

Can anyone help with this problem I have.

I am currently running several programs remotely using ssh. All the remote
programs have been written by myself.

I run the command

ssh remotemachine command >/dev/null 2>/dev/null &

this fires up the command on the remote machine fine. The remote command
basically continues forever without quitting. I need a way to reliably
terminate the remote command. I am presuming the correct way is to issue a
TERM signal to the local ssh command which will force the remote sshd to
quit and thus SIGHUPing the remote command and forcing it to quit.

This appears to happen with some of the programs i have written, but with
others the remote command just continues running in the background. The
remote sshd process does quit in all cases. I'm not doing anything clever
with signals, and I even commented out everything in my main loops and just
left an infinite while loop in there for testing, and it still just goes
into the background and runs forever. I really need these programs to quit
reliably when the controlling terminal is disconnected.

An alternative solution would be to somehow on the local side, get the pid
of the process that sshd fired up at the remote end so I can configure the
stop script to not only TERM the local ssh but also ssh in and TERM the
running process if it failed to quit when sshd did.

This is all running on a Redhat 7.2 system which i believe uses
openssh-2.9p2-7

Any ideas?

Graham Wharton



Relevant Pages