summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-06-14 18:27:45 +0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-06-14 18:27:45 +0800
commit0301cb44137a358b37101a254fb0532a276988a2 (patch)
treed8aeb180b5ca8a0f08ecbc71cfe7fd69b76b9851
parent6bb5a30dbf8335db8d9b8c4e81d652f055deea6a (diff)
downloadpsutil-0301cb44137a358b37101a254fb0532a276988a2.tar.gz
#1536: better detection of zombie proc
-rw-r--r--psutil/_psbsd.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 978ad6c8..bba3a2ba 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -534,6 +534,14 @@ else:
pid_exists = _psposix.pid_exists
+def is_zombie(pid):
+ try:
+ st = cext.proc_oneshot_info(pid)[kinfo_proc_map['status']]
+ return st == cext.SZOMB
+ except Exception:
+ return False
+
+
def wrap_exceptions(fun):
"""Decorator which translates bare OSError exceptions into
NoSuchProcess and AccessDenied.
@@ -648,9 +656,14 @@ class Process(object):
return cext.proc_cmdline(self.pid)
except OSError as err:
if err.errno == errno.EINVAL:
- # XXX: this happens with unicode tests. It means the C
- # routine is unable to decode invalid unicode chars.
- return []
+ if is_zombie(self.pid):
+ raise ZombieProcess(self.pid, self._name, self._ppid)
+ elif not pid_exists(self.pid):
+ raise NoSuchProcess(self.pid, self._name, self._ppid)
+ else:
+ # XXX: this happens with unicode tests. It means the C
+ # routine is unable to decode invalid unicode chars.
+ return []
else:
raise
else: