How to get process status using pid?

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!