Python SIGTERM not killing subprocess -


i have class can start , close process. seems not close process.

my python code, there other methods work fine.:

class kismetinstance:     """creates kismet_server instance"""      def __init__(self, value=false):         logging.basicconfig(format='%(asctime)-15s::: %(message)s')         self.logger = logging.getlogger('kismet_instance')         self.example = value      def __create_kismet_instance__(self):         """         create kismet_server subprocess.         :return:         """         shell = ['sudo', '/usr/local/bin/kismet_server']         self.logger.debug('attempting run: %s', " ".join(shell))         self.kismet = popen(shell, stdin=pipe, stdout=pipe, stderr=pipe, cwd=r'./logs', preexec_fn=os.setsid)       def __destroy_kismet_instance__(self):         """         kill subprocess         :return:         """         os.killpg(os.getpgid(self.kismet.pid), 15) 

it can create subprocess fine. error when try kill (no sudo)

oserror: [errno 1] operation not permitted 

and if run sudo, process still running afterwards.

pi@raspberrypi ~/project $ ps -a | grep 'kismet'  2912 ?        00:00:00 kismet_server 

i managed fix this. turns out subprocess respawning creating weird prevented python keeping track of it.

so had fix it, however not elegant solution, , rather dangerouddangerous.

be careful if use this, because if enter term more broad mine ('kismet') kill lot of processes on system.

def __destroy_kismet_instance__(self):         """         kill subprocess         :return:         """         sig = signal.sigkill # signal send         os.killpg(os.getpgid(self.kismet.pid), sig) # kill 1 of them         p_list = subprocess.popen(['ps', '-a'], stdout=subprocess.pipe) # processes on system         out, err = p_list.communicate()         line in out.splitlines(): # each line (or process)             if 'kismet' in line: # if 'kismet' appears in name                 pid = int(line.split(none, 1)[0]) # process id                 self.logger.debug("found: %d", pid)                 os.killpg(os.getpgid(pid), sig) # kill process 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -