From 103181da19ba0ef92c0c9b332e4c768421a028f4 Mon Sep 17 00:00:00 2001 From: Meliox Date: Sat, 22 Aug 2026 19:51:30 +0200 Subject: [PATCH] fix compile error and reap orphans --- src/modules/node_info/files/ProcessManager.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/node_info/files/ProcessManager.pm b/src/modules/node_info/files/ProcessManager.pm index e858467..919f7da 100644 --- a/src/modules/node_info/files/ProcessManager.pm +++ b/src/modules/node_info/files/ProcessManager.pm @@ -509,7 +509,8 @@ sub _stop_child_collectors { sub _reap_orphaned_collectors { debug(__LINE__, "Scanning for orphaned collector processes from a previous worker"); - unless (opendir(my $dh, '/proc')) { + my $dh; + unless (opendir($dh, '/proc')) { debug(__LINE__, "Failed to open /proc: $!"); return; } @@ -546,19 +547,22 @@ sub _reap_orphaned_collectors { debug(__LINE__, "Sent SIGTERM to orphaned collector PID $pid"); } + # Orphans are already zombies as soon as init reaps them, and kill(0,...) + # keeps reporting a zombie's PID as present - use is_process_alive() so we + # don't spin the full timeout (or send a pointless KILL) on a dead PID. my $timeout = 2; my $start = time(); while (time() - $start < $timeout) { my $any_alive = 0; foreach my $pid (@orphans) { - if (kill(0, $pid)) { $any_alive = 1; last; } + if (is_process_alive($pid)) { $any_alive = 1; last; } } last unless $any_alive; select(undef, undef, undef, 0.1); } foreach my $pid (@orphans) { - if (kill(0, $pid)) { + if (is_process_alive($pid)) { debug(__LINE__, "Force killing orphaned collector process $pid"); kill('KILL', $pid); }