How to get the status of a process using pid?

If I know the pid process, how can I find out if this process is a zombie using Python?

+7
source share
2 answers

You can use the status psutils function:

 import psutil p = psutil.Process(the_pid_you_want) if p.status == psutil.STATUS_ZOMBIE: .... 
+12
source

here's a quick hack using procfs (if you are 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 a 'Z' for zombies.

+11
source

All Articles