From 7030d2e44fccc6c0fc5f5bc87eb05d7134744131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 3 May 2025 13:28:57 +0200 Subject: [PATCH] cgroups: reapp child processes before destroying cgroup killing is enough to destroy a cgroup, we need to remove the wait state of zombie processes before we can destroy the cgroup. --- src/libutil/linux/cgroup.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libutil/linux/cgroup.cc b/src/libutil/linux/cgroup.cc index 4acfe82f1..ae90565a9 100644 --- a/src/libutil/linux/cgroup.cc +++ b/src/libutil/linux/cgroup.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -101,6 +102,11 @@ static CgroupStats destroyCgroup(const std::filesystem::path & cgroup, bool retu // FIXME: pid wraparound if (kill(pid, SIGKILL) == -1 && errno != ESRCH) throw SysError("killing member %d of cgroup '%s'", pid, cgroup); + + while (waitpid(pid, nullptr, 0) == -1) { + if (errno == ECHILD) break; // Process already reaped + if (errno != EINTR) throw SysError("waiting for pid %d", pid); + } } auto sleep = std::chrono::milliseconds((int) std::pow(2.0, std::min(round, 10)));