温馨提示×

centos cmatrix怎么后台跑

小樊
44
2026-08-04 03:08:45
栏目: 智能运维

CentOS 上让 cmatrix 在“后台稳定运行”,常见有几种方式,按“只是暂时挂起”到“真正后台持续运行”给你说明。


一、最简单:用 nohup(推荐)

适合:你只想要它一直跑,不依赖当前终端

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

说明:

  • nohup:忽略 HUP 信号(终端关闭也不会结束)
  • >/dev/null 2>&1:不输出日志
  • &:后台运行

查看是否在跑:

ps -ef | grep cmatrix

结束进程:

pkill cmatrix
# 或
kill PID

二、用 screen(最常用、最实用 ✅)

适合:你以后还想切回来看效果

1️⃣ 安装 screen

yum install -y screen

2️⃣ 新建会话

screen -S matrix

3️⃣ 运行 cmatrix

cmatrix

4️⃣ 离开会话(后台继续跑)

按:

Ctrl + A 然后 D

5️⃣ 重新进入

screen -r matrix

列出所有 screen:

screen -ls

三、用 tmux(更现代)

yum install -y tmux
tmux new -s matrix
cmatrix

离开:

Ctrl + B 然后 D

重新进入:

tmux attach -t matrix

四、systemd 服务(服务器长期运行)

适合:服务器开机自动跑

1️⃣ 创建服务

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

2️⃣ 启动

systemctl daemon-reload
systemctl start cmatrix
systemctl enable cmatrix

五、常见误区 ⚠️

❌ 直接 cmatrix &
→ 终端关闭后进程会被杀掉

❌ 在 SSH 里跑 cmatrix 不挂起
→ 断开 SSH 就结束


推荐方案总结

场景 推荐
临时后台 nohup cmatrix &
可切回查看 screen
服务器长期 systemd
新系统 tmux

如果你是想 服务器开机自动跑 + 不占终端 + 可随时看效果,我可以帮你写一套完整方案。

0