Why were cgroups created when the setrlimit
and getrlimit
system calls already existed?
I thought it might be that rlimit
only applies to a single process, but the man page states:
Limits on the consumption of system resources by the current process and
each process it creates may be obtained with the getrlimit() call, and
set with the setrlimit() call.
It seems to me that if we wanted to control the resource usage of a group of processes, we could just set the limits in a parent process (possibly a shell) and those limits would be enforced in all child processes.
Clearly I'm missing some crucial difference between the two mechanisms, but I couldn't find the answer I was looking for.
Best Answer
This specific wording seems to be mostly used in the *BSD version of
setrlimit
.Other versions of
setrlimit (2)
stateI think this more clearly shows, that a limit of 2 GiB main memory applies to a single process (and its threads). And a child process of this process inherits also a limit of 2 GiB main memory, but this is 2 GiB for its own usage.
In other words, each process would have a limit of 2 GiB, and together they could consume up to 4 GiB of main memory.
On the other side, the man page for cgroups - Linux control groups says
So, control groups allow to limit resources over a group of processes.
Limiting the main memory to 2 GiB for a group containing 3 processes, means the main memory used by all 3 processes together may not exceed 2 GiB.