Re: Annoying, Remote command does not quit when ssh does

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

  • Next message: Rudi Swennen: "Re: keys."
    From: "Graham Wharton" <graham@gwsoft.co.uk>
    Date: Fri, 25 Apr 2003 07:00:22 +0100
    
    

    > It's your local ssh that is backgrounded. The remote command runs
    > in the foreground.

    Yes, This is the bahaviour that I want. Let me explain with an example.

    graham@godber:~$ ssh lucy cat test.c
    Password:
    #include <unistd.h>
    int main()
    {
       while (1)
         {
            sleep(1);
         }
       exit(1);
    }
    graham@godber:~$ ssh lucy gcc -o test test.c
    Password:
    graham@godber:~$ ssh lucy "shopt -s huponexit; ~/test"
    Password:

    Right, the remote program is now running continuously. The local ssh is in
    the foreground, the remote program is also in the foreground.

    graham@godber:~$ ps -x
      PID TT STAT TIME COMMAND
    53236 p0 Is 0:00.05 -bash (bash)
    54394 p0 I+ 0:00.09 ssh lucy shopt -s huponexit; ~/test
    54386 p1 Ss 0:00.03 -bash (bash)
    54395 p1 R+ 0:00.00 ps -x
    graham@godber:~$ ssh lucy ps -x
    Password:
      PID TT STAT TIME COMMAND
    58360 ?? Is 0:00.00 bash -c shopt -s huponexit; ~/test
    58361 ?? S 0:00.00 /home/graham/test
    58407 ?? Rs 0:00.00 ps -x
    graham@godber:~$ ssh lucy ps -ax | grep sshd
    Password:
      229 ?? Ss 0:08.80 /usr/sbin/sshd
    58426 ?? S 0:00.09 sshd: graham@notty (sshd)
    58480 ?? S 0:00.09 sshd: graham@notty (sshd)

    You can see on the remote machine that the test program is running and the
    sshd for it is there.

    graham@godber:~$ kill -TERM 54394
    graham@godber:~$ ps -x
      PID TT STAT TIME COMMAND
    53236 p0 Ss+ 0:00.05 -bash (bash)
    54386 p1 Ss 0:00.05 -bash (bash)
    54423 p1 R+ 0:00.00 ps -x

    The local ssh has now gone.

    graham@godber:~$ ssh lucy ps -x
    Password:
      PID TT STAT TIME COMMAND
    58360 ?? Is 0:00.00 bash -c shopt -s huponexit; ~/test
    58361 ?? S 0:00.01 /home/graham/test
    58464 ?? Rs 0:00.00 ps -x
    graham@godber:~$ ssh lucy ps -ax | grep sshd
    Password:
      229 ?? Ss 0:08.80 /usr/sbin/sshd

    58500 ?? S 0:00.09 sshd: graham@notty (sshd)

    So now, the local ssh and remote sshd has exited correctly, but it still
    leaves the test program running on the remote host. I need the remote
    program to exit when ssh dies.

    Graham


  • Next message: Rudi Swennen: "Re: keys."

    Relevant Pages