在 CentOS 上让 cmatrix 在“后台稳定运行”,常见有几种方式,按“只是暂时挂起”到“真正后台持续运行”给你说明。
nohup(推荐)适合:你只想要它一直跑,不依赖当前终端
nohup cmatrix >/dev/null 2>&1 &
说明:
nohup:忽略 HUP 信号(终端关闭也不会结束)>/dev/null 2>&1:不输出日志&:后台运行查看是否在跑:
ps -ef | grep cmatrix
结束进程:
pkill cmatrix
# 或
kill PID
screen(最常用、最实用 ✅)适合:你以后还想切回来看效果
yum install -y screen
screen -S matrix
cmatrix
按:
Ctrl + A 然后 D
screen -r matrix
列出所有 screen:
screen -ls
tmux(更现代)yum install -y tmux
tmux new -s matrix
cmatrix
离开:
Ctrl + B 然后 D
重新进入:
tmux attach -t matrix
适合:服务器开机自动跑
vim /etc/systemd/system/cmatrix.service
内容:
[Unit]
Description=cmatrix background
[Service]
Type=simple
ExecStart=/usr/bin/cmatrix
Restart=always
StandardOutput=null
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start cmatrix
systemctl enable cmatrix
❌ 直接 cmatrix &
→ 终端关闭后进程会被杀掉
❌ 在 SSH 里跑 cmatrix 不挂起
→ 断开 SSH 就结束
| 场景 | 推荐 |
|---|---|
| 临时后台 | nohup cmatrix & |
| 可切回查看 | screen ✅ |
| 服务器长期 | systemd |
| 新系统 | tmux |
如果你是想 服务器开机自动跑 + 不占终端 + 可随时看效果,我可以帮你写一套完整方案。