fix(node_info): reap zombie pve_mod_worker and orphaned collector processes (#307)
* fix(node_info): reap zombie pve_mod_worker and orphaned collector processes Double-forks pve_mod_worker so it is reparented to init instead of the calling process, which reaps it immediately on exit and prevents it lingering as a <defunct> zombie. Also adds startup-time reaping of orphaned collector-* processes (ppid==1) left behind if a worker was previously killed with SIGKILL, and an opportunistic waitpid(WNOHANG) in _worker_lock_file_exists as a cheap supplemental reap. * fix compile error and reap orphans --------- Co-authored-by: Meliox <na>
This commit is contained in:
1 parent
69e2d78b0a
commit
972c9ae956
2 files changed
+157
-25
No files matched your search
@@ -15,6 +15,7 @@ our @EXPORT_OK = qw(
|
||||
debug
|
||||
read_sysfs
|
||||
is_process_alive
|
||||
get_process_ppid
|
||||
read_lock_pid
|
||||
acquire_exclusive_lock
|
||||
ensure_pve_mod_directory_exists
|
||||
@@ -102,6 +103,24 @@ sub is_process_alive {
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Returns the parent PID of $pid, or undef if it can't be determined.
|
||||
sub get_process_ppid {
|
||||
my ($pid) = @_;
|
||||
return undef unless open my $fh, '<', "/proc/$pid/stat";
|
||||
my $line = <$fh>;
|
||||
close $fh;
|
||||
return undef unless defined $line;
|
||||
|
||||
# comm field (2nd, in parens) can itself contain ')', so split on the
|
||||
# last one before parsing the remaining space-separated fields.
|
||||
my $last_paren = rindex($line, ')');
|
||||
return undef if $last_paren < 0;
|
||||
|
||||
my @fields = split ' ', substr($line, $last_paren + 1);
|
||||
return undef unless defined $fields[1] && $fields[1] =~ /^(\d+)$/;
|
||||
return $1;
|
||||
}
|
||||
|
||||
sub read_lock_pid {
|
||||
my ($lock_path) = @_;
|
||||
|
||||
|
||||
Reference in new issue
Block a user