What is Tmux
TMUX (Terminal Multiplexer) is a program which helps create and manage various terminal sessions created from a terminal itself. We can detach these newly created terminals which helps in asynchronously running multiple programs.
These terminals will keep executing a particular command in the background until we explicitly stop it after attaching it to an active terminal session.
We can create multiple terminal sessions and view and manage them in the same window by toggling between them. Each of these sessions can be detached similarly.
How ML Engineers use TMUX
As ML Engineers, we often perform extensive training on cloud services like AWS or GCP. To do so, we SSH into the VM, giving us a terminal through which we run our training jobs.
Often training a heavy ML model takes days. During this time, if the terminal is disconnected from the VM due to inconsistent network connection or simply if the PC goes into sleep mode, the terminal will disconnect, resulting in abruptly stopping our training job.
This is why it's better to create a tmux terminal from our terminal, run the training job on this new terminal, and detach it. Now even if the terminal is disconnected from the VM, the training job won't stop unless either we stop the VM itself or in case of internet issues.
We can also use terminal windows to manage our terminal commands better. For example, we can use a new terminal window for each of these jobs:
- Git commands
- Docker commands
- To monitor all different processes.
htop -i
- To monitor all the GPU's through
nvidia-smi
- General commands like
ls
andmv
andpip installs
TMUX commands Cheatsheet
Creating and managing terminals
Below commands are for the root terminal:
sudo apt-get install tmux
Installing on Linux environment
tmux ls
List all active sessions
tmux attach -t <name>
Attach a detached session to the current terminal
tmux kill-session -t <name>
Delete a terminal session
tmux new -s <name>
Create a new terminal session
tmux rename-session -t <name> <new-name>
Rename a terminal session
Navigating within an active tmux session
These commands are for navigating your way through when you are inside an active tmux session:
Ctrl + b
- This is prefix for any tmux terminal command
Ctrl + b
+%
Split panes horizontally
Ctrl + b
+—->
,<-—
switch between right and left panes
Ctrl + b
+[
to enter scrolling mode,q
to quit
Ctrl + b
+d
Detach the terminal
Ctrl + b
+c
New terminal instance
Ctrl + b
+space
cycle through the terminal instances
Ctrl + b
+p
orn
previous or next terminal instance
Ctrl + b
+x
kill current pane
A more extensive Cheatsheet can be found here