If I known a process's pid, how can I tell if the process is an zombie using Python ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You could use a the status
feature from psutils:
import psutil p = psutil.Process(the_pid_you_want) if p.status == psutil.STATUS_ZOMBIE: ....
回答2:
here's a quick hack using procfs
(assuming you're using Linux):
def procStatus(pid): for line in open("/proc/%d/status" % pid).readlines(): if line.startswith("State:"): return line.split(":",1)[1].strip().split(' ')[0] return None
this function should return 'Z'
for zombies.