Skip to content

Commit

Permalink
Fix #2236 / NetNBSD: skip terminated process threads
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
giampaolo committed Apr 14, 2023
1 parent a0b096c commit 1946190
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand Down
4 changes: 4 additions & 0 deletions psutil/arch/netbsd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 1946190

Please sign in to comment.