def kill_pid(pid, procname='', daemon=True):
'''Find a PID with optional qualifications and kill it.'''
if pid not in psutil.pids():
return False
for p in psutil.process_iter():
if p.pid != pid:
continue
if procname and p.name() != procname:
continue
if daemon and p.ppid() != 1:
continue
_kill_pid_object(p)
return True
return False
###########################################################################
# Some packages (nscd, nslcd) start their daemons after installation.
# If I'm in an ARM chroot, they live after the chroot exits. Kill them.
# In a cascade situation, sometimes the /proc/<PID>/root link is changed
# to '/some/path (deleted)'. This routine still works.
评论列表
文章目录