nohup 本身只是一个“忽略挂断信号、让进程在后台运行”的命令,它不会自己报错,所谓“nohup 日志报错”通常是指:
用
nohup xxx > log.out 2>&1 &运行程序后,在日志文件里看到错误内容
下面按常见情况 + 处理思路给你一个实用清单。
# 查看 nohup 输出日志
cat nohup.out
# 或你指定的日志
cat log.out
重点看:
nohup: command not found✅ 系统极小概率没有 nohup(极少见)
which nohup
✅ 解决:
# CentOS / Rocky
yum install coreutils
# Ubuntu / Debian
apt install coreutils
nohup: ignoring input and appending output to 'nohup.out'✅ 这不是报错,是正常提示
如果你不想看到:
nohup your_cmd > /dev/null 2>&1 &
Permission denied常见在:
✅ 解决:
chmod +x your_script.sh
或换日志路径:
nohup ./app.sh > /tmp/app.log 2>&1 &
No such file or directory✅ 路径写错或用了相对路径
✅ 建议:
cd /your/app/path
nohup ./start.sh > app.log 2>&1 &
比如:
Exception in thread "main"ModuleNotFoundErrorAddress already in use✅ 处理步骤:
tail -n 50 app.log
java -jar app.jar
# 或
python main.py
可能原因:
✅ 检查:
dmesg | grep -i kill
free -h
df -h
nohup ./your_program > run.log 2>&1 &
查看:
tail -f run.log
退出只看日志,不杀进程:
Ctrl + C
如果频繁遇到日志问题,建议:
systemd 服务(最推荐)supervisorscreen / tmux把 日志里关键报错内容贴出来,例如:
nohup 日志里显示:
java.lang.OutOfMemoryError或Permission denied: /var/log/app.log
我可以一步步告诉你怎么修 ✅