在 Linux 中,nohup 常用来在后台运行程序,并把输出重定向到日志文件。查看日志的方法取决于你启动时是如何重定向的。
nohup python app.py &
nohup.outcat nohup.out
或实时查看:
tail -f nohup.out
nohup python app.py > app.log 2>&1 &
app.logtail -f app.log
说明:
>:标准输出2>&1:错误输出也写入同一文件tail -f 日志文件
例如:
tail -f nohup.out
tail -n 100 nohup.out
cat nohup.out
或分页查看:
less nohup.out
在
less中按q退出,/可搜索
grep "ERROR" nohup.out
如果你不确定日志在哪:
ps -ef | grep 程序名
lsof -p 进程ID
或:
ls -l /proc/进程ID/fd
> nohup.out
或
truncate -s 0 nohup.out
如果你愿意,可以把你具体的 nohup 启动命令发出来,我可以帮你精确指出日志在哪、怎么看。