Tmux使用简介

kuilz 2025-02-12 {工具}

Tmux使用简介

现在一般都通过ssh连接远程服务器训练深度学习模型,为了实现ssh连接断开时仍能继续训练,一般会使用nohup命令在后台运行训练脚本。但如果用的是pytorch框架,运行一段时间后程序仍有可能会中断:

DDP Exception · Issue #67538 · pytorch/pytorch

    raise SignalException(f"Process {os.getpid()} got signal: {sigval}", sigval=sigval)
torch.distributed.elastic.multiprocessing.api.SignalException: Process 102227 got signal: 1

使用tmux可以解决这一问题。

Tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.

基本用法

# ubuntu安装
sudo apt-get install tmux

# 新建会话
tmux new -s <session-name>

# 接入会话
tmux attach -t <session-name>

# 分离窗口,或者用快捷键`Ctrl+b d`,其中`Ctrl+b`为前缀键,用于唤醒快捷键。
tmux detach

# 杀死会话
tmux kill-session -t <session-name>

# 切换会话
tmux switch -t <session-name>

# 列出会话
tmux ls

最简操作流程

1. 新建会话tmux new -s my_session。
2. 在Tmux窗口运行所需的程序。
3. 按下快捷键Ctrl+b d将会话分离。
4. 下次使用时,重新连接到会话tmux attach -t my_session。

开启鼠标滚动

在tmux默认设置中,鼠标是不生效的,因此不能用鼠标滚动页面。执行以下命令开启鼠标滚动:

# 在配置文件添加配置
vim ~/.tmux.conf
set -g mouse on

# 使配置生效
tmux source-file ~/.tmux.conf

References

[1] Home · tmux/tmux Wiki

[2] Tmux 使用教程 - 阮一峰的网络日志

💬评论