I have a script which I run from SSH that launches several processes which I would like to keep open when I disconnect from my session.

Is that feasible? Launching the script in background is not a solution....


My script launches a java process with a different classpath and calls other 4 scripts, each of them launching different java processes with different classpaths.


If the processes are somewhat interactive / not suitable for running as daemons, you're looking for something like GNU Screen or tmux - both of them allow you to start a session with multiple windows in them and detach and reattach that session:

tmux new-session session-1
# start an application
C-b d # C-b means Ctrl-b
# You're now back in your terminal and can disconnect from the server
# After connecting again, use
tmux attach -t session-1
# to get back to your previously created session.

The workflow for screen is similar but I don't know it off the top of my head.

  • which of the one do you suggest? Jul 29 '13 at 14:06
  • I personally use tmux, although the differences between the both of them for non-fancy use cases are really quite small.
    – Wieland
    Jul 30 '13 at 8:46

Depends on what does the "keep open" mean. If you mean you'd like to reconnect some time later and see the output and interact, then Wieland has already provided you a good advice. If you just want them keep running when you exit, you might want to try using nohup: it may be a foreground or background, and it will do the trick.

  • keep each of the subscripts and respective java processes running Jul 29 '13 at 10:38
  • Then please try nohup: it's just a simple wrapper around your custom command you run. It will redirect the output to a file (nohup.out by default, it may appear possible to specify some other file, please check your particular version manual) and it will save the command from being stopped upon terminal disconnection (by blocking the HUP signal).
    – Leonid
    Jul 29 '13 at 14:17

To complete @Wieland's answer, you would use GNU Screen this way :

screen -S session-name
# start your application here
C-a d # C-a means Ctrl and "a" key. 'd' stands for 'detach'
# You're now back in your terminal and can disconnect from the server

# After connecting again, use
screen -r session-name
# to get back to your previously created session.
  • awesome. If I physically go on my server, can I also retrieve the session? Jul 29 '13 at 13:59
  • Yes, assuming you're using a user that has rw on the session file saved (typically) under /tmp, a.k.a. the same user or root, usually.
    – mveroone
    Jul 29 '13 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.