In Linux, processes are grouped into cgroups by:
1️⃣ Creating a cgroup directory in the cgroup filesystem (e.g., /sys/fs/cgroup/mygroup/
).
2️⃣ Adding PIDs of processes you want to include into that cgroup by writing them to the file cgroup.procs
:
echo <pid> > /sys/fs/cgroup/mygroup/cgroup.procs
3️⃣ The kernel then enforces any limits set in that cgroup on all the processes inside it, treating them as a single logical unit for resource control.
Imagine you have:
To group them into a cgroup called myapp
:
mkdir /sys/fs/cgroup/myapp/echo 1000 > /sys/fs/cgroup/myapp/cgroup.procsecho 1001 > /sys/fs/cgroup/myapp/cgroup.procsecho 1002 > /sys/fs/cgroup/myapp/cgroup.procs
Now:
✅ The kernel applies resource limits on myapp → collectively affecting all three processes.
This is where it all ties together beautifully: