在 Debian(以及大多数 Linux 系统)中,使用 nohup 启动程序时,日志的存放路径取决于你命令中是如何重定向的。下面分情况说明:
nohup your_command &
这种情况下:
nohup.out
✅ 查找方式:
ls -l nohup.out
pwd # 看当前目录
nohup your_command > /var/log/myapp.log 2>&1 &
日志就在你写的路径:
/var/log/myapp.log
查看:
tail -f /var/log/myapp.log
nohup your_command > ~/myapp.log 2>&1 &
路径是:
/home/你的用户名/myapp.log
ps aux | grep your_command
ls -l /proc/进程PID/fd
示例:
ls -l /proc/12345/fd
你会看到类似:
1 -> /var/log/myapp.log
2 -> /var/log/myapp.log
lsof -p 进程PID
或
lsof | grep nohup
| 启动方式 | 日志位置 |
|---|---|
nohup cmd & |
当前目录 nohup.out |
> file 2>&1 |
指定文件 |
| 不确定 | /proc/PID/fd 或 lsof |
如果你愿意,可以把你实际运行的 nohup 命令发出来,我可以直接告诉你日志在哪。