在 Linux 下,nohup 通常配合 & 使用来让进程在后台运行,并把输出重定向到日志文件(默认是 nohup.out)。分析 nohup 日志,一般可以从日志位置、查看方式、问题定位、日志管理几个方面入手。
如果你是这样启动的:
nohup python app.py &
日志默认会写到当前目录的:
nohup.out
nohup python app.py > app.log 2>&1 &
>:标准输出2>&1:错误输出也写入同一文件日志就在:
app.log
tail -f app.log
或
tail -F nohup.out
(-F 会在日志被切割后继续跟踪)
tail -n 200 app.log
head -n 100 app.log
grep "ERROR" app.log
tail -f app.log | grep ERROR
grep "2026-01-21 10:" app.log
常见正常日志:
Listening onServer startedstarted successfully异常日志:
Permission deniedAddress already in useModuleNotFoundErrorException重点关注:
TracebackSegmentation faultKilled例如:
grep -n "Traceback" app.log
如果日志中有:
KilledOut of memory可结合:
dmesg | grep -i kill
ps -ef | grep app.py
或
jobs -l
du -h nohup.out
> nohup.out
或
truncate -s 0 nohup.out
用 logrotate 或重定向到带日期的日志:
nohup python app.py > app_$(date +%F).log 2>&1 &
> xxx.log 2>&1[Service]
ExecStart=/usr/bin/python app.py
Restart=always
# 查看进程
ps -ef | grep app.py
# 查看最近错误
tail -n 500 app.log | grep -i error
# 实时观察
tail -f app.log
# 看是否被系统杀掉
dmesg | grep -i oom
如果你愿意,可以把你的 nohup 启动命令 + 日志片段发出来,我可以直接帮你定位问题。