在 CentOS(或其他 Linux)下,用 nohup 启动程序时,默认会把输出写到 nohup.out。如果你想关闭或丢弃输出,可以把标准输出和标准错误重定向到 /dev/null。
nohup your_command >/dev/null 2>&1 &
说明:
>/dev/null:关闭标准输出(stdout)2>&1:把标准错误(stderr)也重定向到 stdout&:后台运行✅ 这样不会生成 nohup.out
nohup your_command >/dev/null &
错误仍可能输出到
nohup.out
nohup your_command 2>/dev/null &
: > nohup.out
或
truncate -s 0 nohup.out
⚠️ 仍在持续写入
停止进程,用下面方式重启:
nohup your_command >/dev/null 2>&1 &
nohup java -jar app.jar >/dev/null 2>&1 &
nohup python3 main.py >/dev/null 2>&1 &
nohup ./start.sh >/dev/null 2>&1 &
lsof -p PID
或
ps -ef | grep your_command
✅ 彻底关闭 nohup 输出:
nohup your_command >/dev/null 2>&1 &
如果你愿意,可以告诉我你运行的是 Java / Python / 自定义程序,我可以给你一个更精确、可复用的启动方案。