Start a long running process in screen and detach¶
- Ssh to the remote host, myremote:
- Start a new screen session
[email protected]:~$ screen
- Start a long running process, "sleep 3600":
[email protected]:~$ sleep 3600
- Detach from the screen session:(Hit [CTRL-A], then type a colon character, then type "detach", then hit [ENTER])
[email protected]:~$ CTRL-A : detach ENTER
- Exit your remote SSH session:
[email protected]:~$ exit
Reattach to the existing screen session¶
- Ssh to the remote host again:
- List your active screen sessions:
[email protected]:~$ 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:
[email protected]:~$ screen -RD
screen -RD 11518.pts-1.myremoteor 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.
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.