在 Debian(以及大多数 Linux 发行版)里,nohup 日志为空通常有下面几类原因,按最常见 → 较少见说明:
这是最常见原因。
nohup command > nohup.out 只捕获标准输出(stdout)✅ 解决:同时重定向 stderr
nohup command > nohup.out 2>&1 &
或:
nohup command &> nohup.out &
有些程序启动后会:
fork()结果:
nohup.out 是父进程写的✅ 解决:
--log-filenohup 的行为是:
nohup.out常见坑:
cd 到别的目录看了sudo 启动,nohup.out 在 root 家目录✅ 建议明确指定路径:
nohup command > /var/log/myapp.log 2>&1 &
某些语言(如 Python、C)会:
✅ 解决:
python -u app.py
flush=Truestdbuf:nohup stdbuf -oL -eL command > log 2>&1 &
日志为空 + 进程不在 = 启动即退出
✅ 排查:
ps aux | grep command
journalctl -xe
dmesg | tail
✅ 检查:
df -h
touch nohup.out
ls -l
nohup your_command > /path/to/app.log 2>&1 &
然后:
tail -f /path/to/app.log
如果你愿意,可以把:
发出来,我可以帮你精准定位为什么是空的。