在 CentOS 上使用 nohup 运行的程序,通常会把输出重定向到日志文件(最常见是 nohup.out 或你自己指定的日志文件)。分析这些日志,一般可以从定位日志、查看内容、过滤关键信息、结合系统工具、定位问题几个方面来做。
nohup command &
默认日志文件:
nohup.out
一般在当前工作目录下。
nohup command > app.log 2>&1 &
日志就在:
app.log
查看进程对应的日志文件:
ps -ef | grep command
ls -l /proc/<PID>/fd
tail -f nohup.out
或
tail -100f app.log
tail -n 200 nohup.out
head -n 100 nohup.out
less nohup.out
G 跳到末尾/关键字 搜索grep "ERROR" nohup.out
grep -i "exception" app.log
grep -C 5 "ERROR" nohup.out
grep -c "ERROR" nohup.out
grep "2026-01-21 10:" nohup.out
ps -ef | grep command
top -p <PID>
free -h
df -h
journalctl -xe
/var/log/messages
重点看:
ExceptionSegmentation faultKilledOutOfMemory可能原因:
du -sh nohup.out
建议:
logrotatenohup command >> /var/log/app/app.log 2>&1 &
并配置 logrotate:
/var/log/app/*.log {
daily
rotate 7
compress
missingok
notifempty
}
如果你愿意,可以把日志片段或命令发出来,我可以帮你具体看是哪种问题(Java / Python / Shell / 服务崩溃等)。