System: treat zombie-only process groups as dead

is_process_group_alive() relied on kill(-pgid, 0), which also succeeds
when every remaining member is a zombie. A supervising ancestor that is
a child subreaper (a build system running tests) can hold those zombies
until it reaps them, so Child::terminate() timed out after SIGKILL even
though the group was dead. On Linux, scan /proc and require a non-zombie
member.

Regression test system_process_group_alive_ignores_unreaped_zombies.
Full vbs test suite passes (VoidTests).
This commit is contained in:
faumaray committed 2026-12-05 12:05:10 +03:00
1 parent 128829bc42
commit c085822686
2 files changed
+87

No files matched your search

@@ -296,6 +296,43 @@ Void::Testing::Test system_replace_file_temp_ownership_and_metrics()
expect(sample.ratio >= 0.0);
}
Void::Testing::Test system_process_group_alive_ignores_unreaped_zombies()
{
// A group whose only members are zombies is dead, even though
// kill(-pgid, 0) still succeeds. This happens whenever a supervising
// ancestor is a child subreaper (e.g. a build system running the tests).
Void::Process::SpawnOptions opts;
opts.executable = VOID_PROCESS_HELPER_PATH;
opts.arguments = {"exit", "0"};
opts.new_process_group = true;
opts.stdin_pipe = false;
opts.stdout_pipe = false;
opts.stderr_pipe = false;
auto spawned = Void::Process::spawn(opts);
require(spawned.has_value());
const auto pid = static_cast<pid_t>(spawned->pid());
bool zombie = false;
for (int attempt = 0; attempt < 400; ++attempt) {
std::ifstream stat{"/proc/" + std::to_string(pid) + "/stat"};
std::string line;
if (std::getline(stat, line)) {
const std::size_t close = line.rfind(')');
if (close != std::string::npos && close + 2 < line.size() &&
line[close + 2] == 'Z') {
zombie = true;
break;
}
}
std::this_thread::sleep_for(std::chrono::milliseconds{5});
}
require(zombie);
expect(!spawned->process_group_alive());
// terminate() reaps the zombie leader and cleans up.
expect(spawned->terminate(std::chrono::milliseconds{50}).has_value());
}
Void::Testing::Test system_terminate_reaps_entire_process_group_after_leader_exits()
{
Void::FileSystem::TempDir tmp{"void_sys_pgid_"};