From 19461905377ce3060b60df1949c082086492dab9 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Fri, 14 Apr 2023 21:38:07 +0000 Subject: Fix #2236 / NetNBSD: skip terminated process threads Process threads() and num_threads() methods now skip threads which are in ZOMBIE or IDLE state. It turns out that after a thread is terminated / join()ed, instead of disappearing it can stick around in a ZOMBIE or IDLE state, presumably for a while before being garbage collected. Signed-off-by: Giampaolo Rodola --- HISTORY.rst | 2 ++ psutil/arch/netbsd/proc.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index d214e61f..324961bc 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -37,6 +37,8 @@ - 2231_, [NetBSD]: *available* `virtual_memory()`_ is higher than *total*. - 2234_, [NetBSD]: `virtual_memory()`_ metrics are wrong: *available* and *used* are too high. We now match values shown by *htop* CLI utility. +- 2236_, [NetBSD]: `Process.num_threads()`_ and `Process.threads()`_ return + threads that are already terminated. 5.9.4 ===== diff --git a/psutil/arch/netbsd/proc.c b/psutil/arch/netbsd/proc.c index b87473a6..e71afb38 100644 --- a/psutil/arch/netbsd/proc.c +++ b/psutil/arch/netbsd/proc.c @@ -247,6 +247,10 @@ psutil_proc_threads(PyObject *self, PyObject *args) { nlwps = (int)(size / sizeof(struct kinfo_lwp)); for (i = 0; i < nlwps; i++) { + if ((&kl[i])->l_stat == LSIDL || (&kl[i])->l_stat == LSZOMB) + continue; + // XXX: we return 2 "user" times because the struct does not provide + // any "system" time. py_tuple = Py_BuildValue("idd", (&kl[i])->l_lid, PSUTIL_KPT2DOUBLE((&kl[i])->l_rtime), -- cgit v1.2.1