From c46d2253e440b1ddcebd3ded64f2bc961bf6034e Mon Sep 17 00:00:00 2001 From: Iurii Trukhin Date: Wed, 14 Oct 2026 19:46:48 +0200 Subject: [PATCH] B #8195: Guard against cpu_j <= 0 and exited PIDs in ProcessList.cpu_info Check cpu_j > 0 and j_end >= cpu_ini[pid] in ProcessList.cpu_info before computing per-process CPU percentage to avoid FloatDomainError (NaN) and negative CPU usage when a process terminates during the sampling window. Signed-off-by: Iurii Trukhin --- src/im_mad/remotes/lib/process_list.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/im_mad/remotes/lib/process_list.rb b/src/im_mad/remotes/lib/process_list.rb index f20c7ccf64..ecf5637801 100644 --- a/src/im_mad/remotes/lib/process_list.rb +++ b/src/im_mad/remotes/lib/process_list.rb @@ -79,8 +79,14 @@ module ProcessList cpu = {} pids.each do |pid| - cpu[pid] = (proc_jiffies(pid) - cpu_ini[pid]) / cpu_j - cpu[pid] = (cpu[pid] * multiplier).round(2) + j_end = proc_jiffies(pid) + + if cpu_j > 0 && j_end >= cpu_ini[pid] + cpu[pid] = (j_end - cpu_ini[pid]) / cpu_j + cpu[pid] = (cpu[pid] * multiplier).round(2) + else + cpu[pid] = 0.0 + end end cpu