See which process is actually hogging your memory inside a cgroup
Container Basics On Linux (Namespaces/Cgroups)
See which process is actually hogging your memory inside a cgroup
🧩 The Challenge
Dealing with a container that keeps getting killed by the OOM killer is infuriating when the logs don’t tell you which specific sub-process inside the cgroup did the heavy lifting. I spent half a day once watching a container flap because I couldn’t pin down the memory spike to one rogue child process.
💡 The Fix
Instead of guessing or running complex monitoring tools, you can query the memory pressure files directly from the cgroup filesystem to find the culprit. It lets you identify the exact PID consuming your RAM before the kernel nukes the whole group.
find /sys/fs/cgroup/memory/system.slice/your-container.service/ -name memory.usage_in_bytes -exec grep -H . {} +
⚙️ Why It Works
The kernel exposes cgroup stats as simple text files in sysfs, so you don’t need external agents to see real-time consumption. By traversing the hierarchy, you can drill down into the specific leaf nodes where individual process memory is being tracked.
🚀 Pro-Tip: Use cgroup v2 if you can; the memory.stat file format is way easier to parse than the v1 mess.
Linux Tips & Tricks | © ngelinux.com | 11/19/2026
