在 Debian 下使用 nohup 运行程序时,日志的定位主要取决于你启动时是怎么重定向的。下面按常见情况说明。
如果你是这样运行的:
nohup your_command &
那么:
nohup.out
$HOME/nohup.out
查看日志:
tail -f nohup.out
# 或
less nohup.out
更规范的做法是显式重定向:
nohup your_command > app.log 2>&1 &
说明:
> app.log:标准输出写到 app.log2>&1:错误也写入同一个文件&:后台运行日志位置:
./app.log
查看:
tail -f app.log
nohup your_command > /dev/null 2> error.log &
日志位置:
./error.log
ps -ef | grep your_command
或:
ps aux | grep your_command
你能看到完整的启动命令行,包括重定向路径。
/proc 查文件描述符假设 PID 是 1234:
ls -l /proc/1234/fd
示例输出:
lr-x------ 1 user user 64 1月 10 10:00 1 -> /home/user/app.log
lr-x------ 1 user user 64 1月 10 10:00 2 -> /home/user/app.log
说明:
1 = stdout2 = stderrlsof 查打开的文件lsof -p 1234 | grep log
如果你其实是用 systemd 启动的(不是 nohup):
journalctl -u your_service.service -f
nohup.outnohup cmd > /var/log/cmd.log 2>&1 &
systemd / supervisor如果你愿意,可以把你的启动命令或ps 输出贴出来,我可以帮你精确判断日志在哪。