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.

1 Answer 1


This specific wording seems to be mostly used in the *BSD version of setrlimit.

Other versions of setrlimit (2) state


A child process created via fork(2) inherits its parent's resource limits. Resource limits are preserved across execve(2).

Resource limits are per-process attributes that are shared by all of the threads in a process.

I 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

Various subsystems have been implemented, making it possible to do things such as limiting the amount of CPU time and memory available to a cgroup, accounting for the CPU time used by a cgroup, and freezing and resuming execution of the processes in a cgroup.

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.

  • The cgroups allows distributing system resources to collections of processes without needing any parent-child relationships and you can limit total memory/CPU/RAM/network usage of the whole group as a whole. Traditional limits only set per process limits and even those limits are best effort. For example limit for real RAM usage no longer works with modern Linux but you have to use cgroup for that. Jun 17, 2022 at 14:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .