Tmux¶
Tmux is a terminal multiplexer that can manage sessions and split screens. Tasks can continue after the remote SSH disconnects, and the session resumes after reconnecting. It is also possible to put processes in the background and take over again when needed. In order to prevent the SSH process from being interrupted due to network disconnection, it is recommended to use the Tmux terminal for all long-running training and other tasks.
The tmux tool has been installed in the official mirror, and commands can be used directly. First create a session.
Executing the command tmux
will create a session numbered 0, and the number of sessions created again will be sorted backwards. Execute tmux new -s <session-name>
to create a session with a custom name. For example, create a session named session1:
tmux new -s session1
After execution, enter the newly created session1 session, and the information of the current session will be displayed at the bottom.
After entering the session, you can execute some long-running commands. When it is necessary to exit the session, leave the session running in the background. You can execute the tmux detach
command, or use the shortcut keys Ctrl + B and then D to exit the session. After exiting the session, the session information at the bottom will disappear, and you will be prompted to log out of the session.
Use the tmux ls
command to view all current sessions.
When you need to restore the session, use tmux a -t <session-name>
to re-enter the previous session, such as entering the session named session1 just now:
tmux a -t session1
When a session needs to be deleted. If you are currently in a session, you can use Ctrl + D or execute logout
to exit the SSH login, that is, to terminate the current session. You can delete a session by executing the following commands when you are not in a session.
# delete the specified session
tmux kill-session -t session1
# delete all sessions
tmux kill-server