From e6b1659df484bd2709d09f62b52851424630c200 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 12 Apr 2023 16:37:41 +0200 Subject: OpenBSD is unable to recognize zombie process. (#2229) OpenBSD is unable to recognize zombie process. It will raise NoSuchProcess instead of ZombieProcess. Test failure: ====================================================================== ERROR: psutil.tests.test_process.TestProcess.test_zombie_process ---------------------------------------------------------------------- Traceback (most recent call last): File "/vagrant/psutil/psutil/_psbsd.py", line 560, in wrapper return fun(self, *args, **kwargs) File "/vagrant/psutil/psutil/_psbsd.py", line 862, in open_files rawlist = cext.proc_open_files(self.pid) ProcessLookupError: [Errno 3] No such process During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/vagrant/psutil/psutil/tests/test_process.py", line 1312, in test_zombie_process zproc.as_dict() File "/vagrant/psutil/psutil/__init__.py", line 528, in as_dict ret = meth() File "/vagrant/psutil/psutil/__init__.py", line 1142, in open_files return self._proc.open_files() File "/vagrant/psutil/psutil/_psbsd.py", line 565, in wrapper raise NoSuchProcess(self.pid, self._name) psutil.NoSuchProcess: process no longer exists (pid=67013) This happens because OpenBSD is the only BSD defining 2 codes for zombie processes: # According to /usr/include/sys/proc.h SZOMB is unused. # test_zombie_process() shows that SDEAD is the right # equivalent. Also it appears there's no equivalent of # psutil.STATUS_DEAD. SDEAD really means STATUS_ZOMBIE. # cext.SZOMB: _common.STATUS_ZOMBIE, cext.SDEAD: _common.STATUS_ZOMBIE, cext.SZOMB: _common.STATUS_ZOMBIE, --- HISTORY.rst | 2 ++ psutil/_psbsd.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index ac50e897..e82605d8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -25,6 +25,8 @@ Matthieu Darbois) - 2225_, [POSIX]: `users()`_ loses precision for ``started`` attribute (off by 1 minute). +- 2229_, [OpenBSD]: unable to properly recognize zombie processes. + `NoSuchProcess`_ may be raised instead of `ZombieProcess`_. 5.9.4 ===== diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index a25c96cd..a0f07ee2 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -545,7 +545,7 @@ else: def is_zombie(pid): try: st = cext.proc_oneshot_info(pid)[kinfo_proc_map['status']] - return st == cext.SZOMB + return PROC_STATUSES.get(st) == _common.STATUS_ZOMBIE except Exception: return False -- cgit v1.2.1