How to start a long-running process in screen and detach from it
Start a long running process in screen and detach¶
- Ssh to the remote host, myremote:
eliot@mylocal:~$ ssh myremote
- Start a new screen session
eliot@myremote:~$ screen
- Start a long running process, "sleep 3600":
eliot@myremote:~$ sleep 3600
- Detach from the screen session:(Hit [CTRL-A], then type a colon character, then type "detach", then hit [ENTER])
eliot@myremote:~$ CTRL-A : detach ENTER
- Exit your remote SSH session:
eliot@myremote:~$ exit
Reattach to the existing screen session¶
- Ssh to the remote host again:
eliot@mylocal:~$ ssh myremote
- List your active screen sessions:
eliot@myremote:~$ screen -ls There is a screen on: 11518.pts-1.myremote (Detached) 1 Socket in /var/run/screen/S-eliot.
- Reattach to your screen session:Note: you don't actually have to use the -RD option. You could use -rD or -r. But I just use -RD all the time. If there is more than one screen session active you will have to say:
eliot@myremote:~$ screen -RD
screen -RD 11518.pts-1.myremote
or whichever screen session you want to attach to. - It will show you the "sleep 3600" command running. To exit, CTRL-C the sleep process, type "exit" to exit the screen session, and "exit" again to exit the SSH session.
See also¶
- For more information, see the screen man page or the GNU Screen User's Manual
- See also my post, How to scroll in GNU Screen
Comments
screen was somehow deprecated if I remember correctly. tmux seems to be a more up to date alternative.
jnns: I guess I am behind the times. tmux looks really good-- I will have to give it a try.
- Is tmux the GNU Screen killer? | TechRepublic
- tmux, a BSD alternative to GNU Screen - Niall's blog
- switching from gnu screen to tmux | Linux~ized
- tmux vs. screen - Super User
- Why You Should Try tmux Instead of screen - Dominik Honnef
- Screen vs. tmux Faceoff - UTOSC 2012 - End Point Corporation
- Interview with Nicholas Marriott on tmux - OpenBSD Journal
- Tmux – the Terminal multiplexer - Linuxaria
Instead of hitting : and typing "detach" you can also just do ctrl+a d
. That will detach you instantly.
Also when reaching, checkout -X
option, Then you can view/type in it from multiple terminals.
Also, if you like tmux, checkout byobu.