From 97d2284534fe1ebafd4bf466461390e7b0a66d7f Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 24 May 2020 22:42:41 +0200 Subject: maybe we have a zombie process detection on OSX --- psutil/_psosx.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'psutil/_psosx.py') 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: -- cgit v1.2.1