繁体   English   中英

为什么即使退出腻子后我的python脚本仍在EC2上的背景中运行?

[英]Why is my python script still running in the backgroud on EC2 even after I quit putty?

根据SE上的这个问题 ,除非我使用nohupscreen ,否则我运行的脚本应在终端会话中终止。 但是当我

sudo python b.py &

b.py是:

from time import gmtime, strftime
import datetime
import time
import sys
import logging

logging.basicConfig(filename='test.log',level=logging.WARNING,format='%(message)s')
logging.warning('start')

while True:
    s = (datetime.datetime.now().minute) *60 + datetime.datetime.now().second
    if ((s)%(60*5) <= 6) : #True: #
        logging.error((strftime("%Y-%m-%d %H:%M:%S", gmtime()))) 
    time.sleep(5)

然后

exit

并再次使用腻子登录, test.log仍在更新中,当我这样做时

ps -Alf | grep python,

流程显示:

4 S root     11179     1  0  80   0 - 16974 poll_s 15:44 ?        00:00:00 sudo python b.py
4 S root     11180 11179  0  80   0 - 10652 poll_s 15:44 ?        00:00:00 python b.py

尽管jobs命令不返回任何内容。

为什么会这样呢? 根据他人的经验, b.py在我退出终端时应该已经停止。 我在微型实例上使用Ubuntu AMI。

谢谢!

&会将其放在后台,因此它将继续运行直到pid被杀死为止,并且由于您使用sudo运行了它,因此您也需要使用sudo杀死pid。

杀死-9 11179

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM