温馨提示×

centos如何后台运行cmatrix

小樊
43
2026-10-03 01:59:18
栏目: 智能运维

在 CentOS 中让 cmatrix 在后台运行,常见有几种方式,取决于你是“只是不想占终端”还是“断开 SSH 也能跑”。


一、最简单:用 &(断开终端会停)

cmatrix &
  • 程序在后台运行
  • 但 关闭终端 / 断开 SSH 会结束

适合临时看效果。


二、推荐:用 nohup(断开 SSH 也运行)

nohup cmatrix > /dev/null 2>&1 &

或保存输出:

nohup cmatrix > cmatrix.log 2>&1 &

查看进程:

ps aux | grep cmatrix

结束进程:

kill -9 $(pidof cmatrix)

✅ 最常用方式


三、用 setsid(完全脱离终端)

setsid cmatrix

或

setsid cmatrix > /dev/null 2>&1 < /dev/null &

即使退出 SSH 也不会停。


四、用 screen(可随时回看)

yum install -y screen
screen
cmatrix
  • Ctrl + A 然后 D 脱离
  • 重新进入:
screen -r

✅ 适合“想随时回来看动画”


五、开机自启(可选)

crontab -e

添加:

@reboot cmatrix > /dev/null 2>&1

⚠️ 注意:cmatrix 需要 终端(tty),纯无桌面环境可能不会显示。


总结推荐

需求 命令
临时后台 cmatrix &
断开 SSH 也跑 nohup cmatrix &
随时回看 screen
完全脱离 setsid cmatrix

如果你是 服务器无桌面环境,说明一下,我可以告诉你怎么用 tmux 或伪终端方式跑。

0 踩