2019+ Introduction to Linux Command line course run by CRUK https://tinyurl.com/cruk-linux
View the Project on GitHub bioinformatics-core-shared-training/Intro-linux-command-line
Depending on how you connect to a Remote computer/the cloud, you may have processes and jobs that are
running, and will need to continue running for some time. If you are connecting to your
Remote computer/cloud desktop via VNC, jobs you start will continue to run. If you are connecting via SSH,
if you end the SSH connection (e.g. you exit your SSH session, you lose your connection
to the internet, you close your laptop, etc.), jobs that are still running when you
disconnect will be killed. There are a few ways to keep Remote computer/cloud processes running in the background.
Many times when we refer to a background process we are talking about what is
described at this tutorial -
running a command and returning to shell prompt. Here we describe a program that will
allow us to run our entire shell and keep that process running even if we disconnect: tmux
. If you don’t have tmux
on your system, you should still be able to use screen
. This is another program that has mostly the same capabilities as tmux
. It’s a lot older, though, so can be more clunky to use; however, it is likely to be available on any Remote computer/cloud system you encounter.
In both tmux
and screen
, you open a ‘session’. A ‘session’ can be thought of as a window for tmux
or screen
, you might open an terminal to do one thing on the a computer and then open a new terminal to work on another task at the command line.
As you work, an open session will stay active until you close this session. Even if you disconnect from your machine, the jobs you start in this session will run till completion.
For the following instructions use either tmux
OR screen
, not both!
You can start a session and give it a descriptive name:
tmux
$ tmux new -s session_name
screen
$ screen -S session_name
This creates a session with the name session_name
which will stay active until you close it.
You can detach from a session by pressing on your keyboard:
tmux
: control + b
followed by d
(for detach)screen
: control + a
followed by d
(for detach)If you disconnect from your session, or from your ssh into a machine, you will need to reconnect to an existing session. You can see a list of existing sessions:
tmux
$ tmux list-sessions
screen
$ screen -ls
To connect to an existing session:
tmux
$ tmux attach -t session_name
The -t
option = ‘target’
screen
$ screen -r session_name
The -r
option = ‘resume a detached screen session’
You can switch between sessions:
tmux
$ tmux switch -t session_name
You can end sessions:
tmux
$ tmux kill-session -t session_name
screen
$ screen -r session_name
$ exit