def terminateChildrenPidOnly(self, pid, signals=(signal.SIGINT, signal.SIGTERM)):
ls = commands.getoutput('ls /proc')
entries = ls.split('\n')
for entry in entries:
filename = '/proc/'+entry+'/status'
try:
fp = open(filename,'r')
stuff = fp.readlines()
fp.close()
except:
continue
ret = ''
for line in stuff:
if 'PPid' in line:
ret=line
break
if ret != '':
parentPid = ret.split('\t')[-1][:-1]
if parentPid == pid:
self.terminateChildrenPidOnly(entry, signals)
filename = '/proc/'+pid+'/status'
for sig in signals:
try:
os.kill(int(pid), sig)
except:
continue
done = False
attemptCount = 0
while not done:
try:
fp = open(filename,'r')
fp.close()
attemptCount += 1
if attemptCount == 10:
break
time.sleep(0.1)
except:
done = True
if not done:
continue
评论列表
文章目录