(一)问题描述:python
nohup 你的程序命令shell
如:centos
nohup python manage.py runserver 0.0.0.0:6789 (此shell窗口1不要关,另外开一个shell窗口2查看nohup.out)缓存
能够将你的程序放到后台运行,不至于关闭shell窗口后,程序终止。bash
可是此时的nohup.out中却没有记录任何shell窗口的输出日志。app
这是怎么回事呢???centos7
(二)分析:.net
经过反复试验,我发现。日志
日志不是不往nohup.out文件中写,而是日志信息会被先存到Linux的缓存中去,等到缓存中的数据达到必定量后,才会写到nohup.out中去。server
不信,你把nohup python manage.py runserver 0.0.0.0:6789 程序所在shell窗口1用ctrl+c来终止它,你回头再到shell窗口2中看看nohup.out,是否是有日志信息了。
ps:不要用kill杀程序,否则看不到从缓存中写入nohup.out中的日志信息。
那么,解决nohup.out中没有日志写入,或者写入不及时(实时)的方法就是,杜绝缓存机制。
(三)解决方案:
shell窗口1中:
export PYTHONUNBUFFERED=1 nohup python manage.py runserver 0.0.0.0:6789
ps:忽略以下错误提示:
nohup: ignoring input and appending output to ‘nohup.out’
shell窗口2中:
此时你再查看nohup.out,是否是有日志实时写入了!!!
参考:https://blog.csdn.net/epeaktop/article/details/82665481
ps:以上操做在centos7上进行的,其余版本不知道有没有差别,若有不一样,请留言,若有用,请点赞推荐,多谢。