Stop your cgroups from hoarding orphan tasks after a process dies
Container Basics On Linux (Namespaces/Cgroups)
Stop your cgroups from hoarding orphan tasks after a process dies
🧩 The Challenge
Dealing with cgroup v2, I’ve found that even after a container process dies, some of those processes hang around in a zombie state and lock up the controller. It’s infuriating when you try to clean up a slice and the kernel just tells you the directory isn’t empty.
💡 The Fix
You need to tell the kernel to stop being so stubborn by setting the memory.high or kill switches, but mostly you just need to ensure you are manually triggering a recursive kill on the subtree before trying to remove the cgroup directory.
echo 1 > /sys/fs/cgroup/your_group/cgroup.kill
⚙️ Why It Works
Setting this file tells the kernel to send a SIGKILL to every single process currently trapped inside that specific control group. It clears out the stragglers so the hierarchy finally becomes deletable.
🚀 Pro-Tip: Always double-check your child cgroup controllers are drained before trying to rmdir the parent.
Linux Tips & Tricks | © ngelinux.com | 7/28/2026
