diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-24 22:42:41 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-05-24 22:42:41 +0200 |
commit | 97d2284534fe1ebafd4bf466461390e7b0a66d7f (patch) | |
tree | 453f9ec7ae9e7abc9f400d849dac820bb4c3d4fa | |
parent | 7d081114d708c60761e355c555d73ea29460d9a0 (diff) | |
download | psutil-wheel5.tar.gz |
maybe we have a zombie process detection on OSXwheel5
-rw-r--r-- | psutil/_psbsd.py | 12 | ||||
-rw-r--r-- | psutil/_psosx.py | 13 |
2 files changed, 18 insertions, 7 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index 49ad1e99..d53eb042 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -551,10 +551,10 @@ def wrap_exceptions(fun): try: return fun(self, *args, **kwargs) except ProcessLookupError: - if not pid_exists(self.pid): - raise NoSuchProcess(self.pid, self._name) - else: + if is_zombie(self.pid): raise ZombieProcess(self.pid, self._name, self._ppid) + else: + raise NoSuchProcess(self.pid, self._name) except PermissionError: raise AccessDenied(self.pid, self._name) except OSError: @@ -576,10 +576,10 @@ def wrap_exceptions_procfs(inst): # ENOENT (no such file or directory) gets raised on open(). # ESRCH (no such process) can get raised on read() if # process is gone in meantime. - if not pid_exists(inst.pid): - raise NoSuchProcess(inst.pid, inst._name) - else: + if is_zombie(inst.pid): raise ZombieProcess(inst.pid, inst._name, inst._ppid) + else: + raise NoSuchProcess(inst.pid, inst._name) except PermissionError: raise AccessDenied(inst.pid, inst._name) diff --git a/psutil/_psosx.py b/psutil/_psosx.py index e4296495..2feff932 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -324,6 +324,14 @@ def pids(): pid_exists = _psposix.pid_exists +def is_zombie(pid): + try: + st = cext.proc_kinfo_oneshot(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. @@ -333,7 +341,10 @@ def wrap_exceptions(fun): try: return fun(self, *args, **kwargs) except ProcessLookupError: - raise NoSuchProcess(self.pid, self._name) + if is_zombie(self.pid): + raise ZombieProcess(self.pid, self._name, self._ppid) + else: + raise NoSuchProcess(self.pid, self._name) except PermissionError: raise AccessDenied(self.pid, self._name) except cext.ZombieProcessError: |