I know those two mechanisms (let's call them A and B) limit the resource for a process.
I want to know the cooperation of those two.
If A limits a resource for a process, then what happens when B also limits the same resource?
All limits apply independently. When a process makes a request that would require going over some limit, the request is denied. This holds whether the limit is for a cgroup, per process, or per user.
Since cgroup sets limits per groups of processes, and setrlimit sets limits per user or per process, the mechanisms are generally not redundant. It's possible for a given request to exceed both cgroup and setrlimit limits, or only one of them.
Keep in mind that all limits are maximum allowed values, not guaranteed minimums. For example, if there's a limit to 1GB of memory per process, a process with 200MB of memory may still get its request to allocate 100MB denied if there's no more available memory in the system, regardless of any applicable limits. If a setrlimit and a cgroup limit both apply, then that's at least three maximums that can be exceeded: the setrlimit maximum, the cgroup maximum, and the currently available resource maximum.
ulimit shell command (executable program) is a wrapper around the
setrlimit system call (function provided by the kernel), and the underlying data structure which contains the limit information is called
ulimit shell command controls the soft and hard limits over the resources available to the shell and to processes started by it.
setrlimit() system calls get and set resources limits respectively, where the assicoated soft and hard limits are defined by the
For more information, use:
man 1 ulimit and
man 2 setrlimit
Cgroups (Control Groups) allow you to allocate resources — such as CPU time, system memory, network bandwidth, or combinations of these resources — among user-defined groups of tasks (processes) running on a system.
ulimit has nothing to do with per-process settings or anything related to throttling velocities. This is what
cgroups kernel extension is capable of and is used for. To mention one of the other features it provides, we can say it can even allow hierarchies of settings to be defined.