在 CentOS 上让 cmatrix 在后台运行,常见有几种方式,取决于你是“只是不想占用终端”还是“退出 SSH 也能继续跑”。
cmatrix &
& 让程序后台运行nohup cmatrix > /dev/null 2>&1 &
查看进程:
ps aux | grep cmatrix
setsid cmatrix > /dev/null 2>&1
yum install -y screen
screen
cmatrix
然后按:
Ctrl + A 再按 D
screen -r
yum install -y tmux
tmux
cmatrix
退出会话:
Ctrl + B 再按 D
重新进入:
tmux attach
如果你希望 ** CentOS 启动就跑 cmatrix**(一般不推荐服务器):
创建 service(示例):
vim /etc/systemd/system/cmatrix.service
[Unit]
Description=CMatrix
[Service]
ExecStart=/usr/bin/cmatrix
Restart=always
[Install]
WantedBy=multi-user.target
systemctl enable --now cmatrix
| 场景 | 推荐方式 |
|---|---|
| 临时后台 | cmatrix & |
| 退出终端还在 | nohup cmatrix & |
| 可随时切回 | screen / tmux |
| 服务器常驻 | systemd |
如果你是 服务器无桌面环境,注意:cmatrix 需要 终端(tty),在纯后台可能无法显示动画效果。
需要我帮你写一键脚本吗?