Skip to content

Commit

Permalink
#1536: better detection of zombie proc
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jun 14, 2019
1 parent 6bb5a30 commit 0301cb4
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,14 @@ def pid_exists(pid):
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.
Expand Down Expand Up @@ -648,9 +656,14 @@ def cmdline(self):
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:
Expand Down

0 comments on commit 0301cb4

Please sign in to comment.