nohup 后台运行脚本,且可以实时查看日志

如果是使用 nohup python abc.py > nohup.log 2>&1 & 的话,可以将日志写入到nohup.log文件,但是没法实时用tail -f nohup.log来查看日志。

解决方法:
nohup python -u abc.py > nohup.log 2>&1 &
因为python会将日志放到缓存中,等程序执行完成后或者日志达到一定的长度到才写入文件,这个时候加参数“-u”就可以用tail -f nohup.log来实时查看日志了。

原文地址:https://www.cnblogs.com/lanlingshao/p/10260600.html