在 CentOS 中使用 nohup 启动程序时,日志和错误通常有以下几种情况和查找方式:
nohup.out如果你是这样启动的:
nohup your_command &
默认会把 标准输出(stdout)和标准错误(stderr) 都写到当前目录的:
nohup.out
查看错误:
tail -f nohup.out
# 或查看全部
cat nohup.out
如果你这样启动:
nohup your_command > app.log 2>&1 &
错误和正常输出都在:
app.log
查看:
tail -f app.log
如果只分离了错误:
nohup your_command > app.log 2> error.log &
错误在:
error.log
ps -ef | grep your_command
或
jobs -l
如果进程已经退出:
echo $?
(仅对刚结束的命令有效)
# 通用
journalctl -xe
# 老版本 CentOS
tail -f /var/log/messages
# 如果是 Java / 服务
tail -f /var/log/dmesg
dmesg | grep -i killed
或
grep -i oom /var/log/messages
nohup your_command > run.log 2>&1 &
或者按日期:
nohup your_command > run_$(date +%Y%m%d).log 2>&1 &
# 只看错误(如果有分开日志)
grep -i error error.log
# 实时看最新错误
tail -f app.log | grep -i error
如果你愿意,可以把:
nohup.out 或日志内容片段发出来,我可以直接帮你判断错误原因。