nohup 本身不是日志工具,它只是“忽略挂断信号(SIGHUP)”并默认把输出重定向到一个文件。如果你“没看到日志”,通常有以下几种常见原因:
很多人这样写:
nohup python app.py &
这时:
nohup.out✅ 正确写法(推荐):
nohup python app.py > app.log 2>&1 &
或
nohup python app.py >> app.log 2>&1 &
即使你重定向了:
printlogging,但你没配置 handler✅ Python 防缓冲:
nohup python -u app.py > app.log 2>&1 &
常见误区:
/var/logls -l nohup.out
ls -l app.log
例如:
这些错误可能:
nohup.out✅ 检查进程:
ps -ef | grep app.py
如果你在:
那 nohup 基本没用,日志由它们接管。
nohup 不保证有日志,它只是“不挂断 + 默认可能写 nohup.out”
✅ 最稳妥写法:
nohup your_command > run.log 2>&1 &
如果你愿意,可以把你的**完整命令 + 环境(Linux? Docker? Python?)**发出来,我可以直接帮你定位。