分析 nohup 日志异常,通常可以按下面这套思路和方法来做。
使用 nohup 启动时,默认输出会写到:
nohup command > nohup.out 2>&1 &
或显式指定:
nohup command > app.log 2>&1 &
常见位置:
nohup.out(当前目录)app.log)/dev/null(如果被丢弃,就很难排查)先确认:
ls -lh nohup.out app.log
tail -n 200 nohup.out
tail -f nohup.out
grep -iE "error|exception|fail|stack|timeout|killed" nohup.out
常见异常信号:
Exception / ErrorSegmentation faultOutOfMemoryErrorKilledConnection refusedTimeout检查进程:
ps -ef | grep your_app
若进程不在,但日志有:
Killed → 可能是 OOM(内存不足)Segmentation fault → 程序本身 bug查看系统日志:
dmesg | tail
# 或
journalctl -xe
排查:
top -p <pid>
或:
strace -p <pid>
例如:
重点看:
grep -n "ERROR" nohup.out
grep "2026-01-21 10:" nohup.out
grep -c "Exception" nohup.out
awk '/Exception/{flag=1} flag{print} /^\}$/{flag=0}' nohup.out
避免 nohup.out 无限增大:
logrotate
或:
nohup command >> app.log 2>&1 &
| 现象 | 可能原因 |
|---|---|
| 日志为空 | 输出被重定向到 /dev/null |
| 进程消失 | OOM / 被 kill |
| 中文乱码 | 编码不一致 |
| 日志不刷新 | 缓冲未 flush |
| 多进程写同一文件 | 日志错乱 |
ps 看进程是否还在tail -f 看实时日志grep Error/Exceptiondmesg 看是否被系统杀如果你愿意,可以把 日志片段 / 启动命令 / 程序类型(Java? Python? C++?) 发出来,我可以帮你具体分析。