tmux : Terminal Multiplexer
tmux utility allows us to protect long running processes from being killed by network failures.
tmux is a terminal multiplexer, so it can do a lot more than just the use case described here, including allowing us to run multiple screens and using split screens, but the main thing that is important to me is to protect work from network disconnections.
The installation is really simple.
# dnf install -y tmux
The most important use case for me is to create a new session to do some specific work that absolutely must not fail, even if a network failure occurs. We don't need to name sessions, as
tmux will automatically name them sequentially with a number starting from zero. We are going to ignore this automatic naming, as it can become confusing if you have many people working on the same server, or you are using multiple windows. Instead we can use named sessions, where the name gives meaning to the work being carried out by the session.
$ tmux new -s oracle-install
There are a couple of things that could happen now.
- You want to detach from the session and leave your PC, without killing the running process.
- Your connection to the server dies and you don't want your process to end.
How do you deal with these?
- If you want to manually detach, just do CRTL+B and then D. Your session will continue, but you are detached from it.
- Pull the plug on your network, wifi or VPN, and you can simulate this type of problem.
When you get back to your system, what do you do?
List the sessions that are available.
$ tmux list-windows -a oracle-install:0: bash* (1 panes) [103x24] $
You can then reattach to the screen and continue your work.
$ tmux attach-session -t oracle-install
When the work is done you can exit the screen by using
exit command, just like you are exiting SSH, or use CTRL+B, and then X. You will be prompted to confirm. Press Y to confirm.
If you don't want to name your sessions you don't have to. Just start a new session with out a name.
Detach the session using CTRL+B and D, then check the list of sessions.
$ tmux list-windows -a 0:0: bash* (1 panes) [103x24] $
You can then reattach in the same way we saw before.
$ tmux attach-session -t 0
As mentioned previously, the
tmux utility can do much more than this one use case. If you are interested in using multiple screens, check out the tmux Wiki.
For more information see:
Hope this helps. Regards Tim...