Stop cgroups from trapping your runaway processes
Container Basics On Linux (Namespaces/Cgroups)
Stop cgroups from trapping your runaway processes
🧩 The Challenge
Dealing with a Java service that keeps leaking memory and spawning child processes is a nightmare when the parent decides to zombie out. Trying to hunt down every single thread and orphaned child so I can finally restart the damn thing is how I’ve wasted half my weekends.
💡 The Fix
Instead of playing whack-a-mole with PID lists, just use the cgroup freezer state or look at the process list directly inside the cgroup’s specific hierarchy to kill the whole tree at once.
echo 1 > /sys/fs/cgroup/memory/my_service/cgroup.freeze
cat /sys/fs/cgroup/memory/my_service/cgroup.procs | xargs kill -9
⚙️ Why It Works
Writing to the freezer state stops all processes in that group cold, preventing them from spawning more forks while you are trying to clean up. It’s way cleaner than blindly sending signals to a process that might have already spawned fifty children you can’t even see.
🚀 Pro-Tip: Use systemd-cgls if you want to see the hierarchy without squinting at sysfs directly.
Linux Tips & Tricks | © ngelinux.com | 8/4/2026
