nohup 日志不显示,通常是因为输出没写到你以为的文件里,或者程序还没真正输出。下面按常见原因给你排查思路(Linux 环境)。
很多人以为 nohup 默认一定写 nohup.out,其实不一定。
nohup python app.py
但你在代码里用了:
print("xxx", flush=False)
或者日志框架把日志写到了别的地方。
✅ 建议显式重定向
nohup python app.py > app.log 2>&1 &
这是最容易被忽略的!
tail -f 看不到内容✅ 解决办法
Python
nohup python -u app.py > app.log 2>&1 &
或代码里:
print("xxx", flush=True)
Java
nohup java -jar app.jar > app.log 2>&1 &
或加:
-Djava.util.logging.config.file=logging.properties
nohup python app.py > nohup.out &
❌ 这样 stderr 不会进 nohup.out
✅ 正确写法
nohup python app.py > nohup.out 2>&1 &
lsof -p <PID> | grep -E 'txt|log|out'
ls -l /proc/<PID>/fd
常见:
1 → stdout2 → stderrnohup command &
nohup.out$HOME/nohup.outnohup ./your_program > run.log 2>&1 &
tail -f run.log
nohup python -u app.py > app.log 2>&1 &
stdbufnohup stdbuf -oL -eL ./app > app.log 2>&1 &
如果你愿意,可以把:
贴出来,我可以直接帮你定位是哪一条原因。