Reputation: 11
According to this question on SE, the script I run should be terminated with my terminal session, unless i use nohup
or screen
. However when I
sudo python b.py &
with b.py
being:
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)
then
exit
and log in using putty again, the test.log
is still being updated, and when i do
ps -Alf | grep python,
the processes show up:
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
although jobs
command doesn't return anything.
why is it so? according to other's experience b.py
should have stopped when i logged out of the terminal. I'm using the Ubuntu AMI on a micro instance.
Thanks!
Upvotes: 1
Views: 1288
Reputation: 36
The & puts it in the background, so it will continue to run until it's pid is killed, and since you ran it with sudo you will need to kill the pid with sudo as well.
kill -9 11179
Upvotes: 1