温馨提示×

centos cmatrix如何后台运行

小樊
49
2026-10-17 16:07:34
栏目: 智能运维

在 CentOS 上让 cmatrix 在后台运行,常见有几种方式,取决于你是“只是不想占用终端”还是“退出 SSH 也能继续跑”。


一、最简单:终端后台运行(不退出终端)

cmatrix &
  • & 让程序后台运行
  • 终端还能继续用
  • 缺点:关闭终端,cmatrix 会结束

二、退出终端也不退出(推荐)

方法 1:nohup

nohup cmatrix > /dev/null 2>&1 &
  • 退出 SSH / 终端仍然运行
  • 输出被丢弃(cmatrix 是图形界面程序,一般不需要输出)

查看进程:

ps aux | grep cmatrix

方法 2:setsid(更干净)

setsid cmatrix > /dev/null 2>&1
  • 直接脱离终端
  • 不受 hangup 影响

三、使用 screen(最常用、可随时切回)

yum install -y screen
screen
cmatrix

然后按:

Ctrl + A 再按 D
  • detach 后台
  • 重新进入:
screen -r

四、使用 tmux(更现代)

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),在纯后台可能无法显示动画效果。

需要我帮你写一键脚本吗?

0 踩