2

I ssh in to my ubuntu machine usimg mobaxterm.

This works very well.

Sometimes I want to keep a process running but exit my ssh session (and exit mobaxterm). I have tried the following but regardless as soon as I close mobaxterm my process on the target machine dies, using firefox as an example:

ssh => 
tmux;
firefox & disown;
tmux detach;
exit;

ssh => 
screen firefox & disown;
exit;

I'm sure I've made a really stupid mistake but looking around other posts on this topic I thought I had followed their recomendations but to no evail.

thanks in advance.

Clarification: I can detach my process succesfully using screen or nohup, but is it possible to shut the ssh client and keep the detached process running?

lazarus
  • 121
  • 1
  • 3
  • also have a look at disown http://serverfault.com/questions/34750/is-it-possible-to-detach-a-process-from-its-terminal-or-i-should-have-used-s?rq=1 – bgtvfr Mar 06 '17 at 10:21
  • Possible duplicate of [Can I nohup/screen an already-started process?](http://serverfault.com/questions/24425/can-i-nohup-screen-an-already-started-process) – user9517 Mar 06 '17 at 10:24
  • 1
    Do I read that right, that you start firefox with X11 forwarding and when you close the connection, you are surprised, that the firefox does not continue to run in your session? – Jakuje Mar 06 '17 at 12:44

2 Answers2

1

Two options to avoid automatic killing a detached process:

  1. Using screen: screen is an Unix utility which allows you to keep a live session, after your logged-out.

    • To start screen, enter the following command:

    screen

    • Detach but keep shell window open

    press Ctrl a d

    • Resume your screen session:

    screen -r

You should use screen in the following way:

  1. ssh into the server
  2. start screen
  3. execute the commands you want to run
  4. detach screen (ctrl-a-d)
  5. exit the server andclose ssh connection

The processes should keep running in the server

You'll be able to see it, when you'll:

  1. ssh into the server
  2. resume screen screen -r
  3. check relevant logs, ps -ef , etc

More info:

More info: - man nohup

Yaron
  • 221
  • 2
  • 3
  • 15
  • As per my op, I've tried screen, I've also tried nohup, but when I exit my ssh client (mobaxterm) the process I started is killed. So I suppose what I am asking is, is it possible to shut the ssh client and keep the detached process running? – lazarus Mar 06 '17 at 10:25
  • @danm - screen should work, I've updated my answer with step-by-step instructions how to use screen – Yaron Mar 06 '17 at 10:30
0

Clarification: I can detach my process succesfully using screen or nohup, but is it possible to shut the ssh client and keep the detached process running?

Yes.

This is remarkably easy to test for yourself too.

user9517
  • 114,104
  • 20
  • 206
  • 289