Linux for Developers Course
Linux for Developers
/
Advanced

cgroups (Control Groups)

Definition

A Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network) of a collection of processes.

Explain Like I'm New

The resource manager. It allows you to put a strict limit on an application, saying 'This database is never allowed to use more than 2 Gigabytes of RAM, no matter what.'

Real World Example

If you run `docker run --memory="500m" nginx`, Docker doesn't magically restrict the memory. Docker talks to the Linux Kernel and creates a `cgroup` with a 500MB limit, and puts the Nginx process inside that group.

Common Use Cases

  • •Preventing apps from crashing the server via memory leaks
  • •Docker resource limiting

Interview Questions

basic

  • What happens if a process inside a memory-limited cgroup tries to use more RAM than it is allowed?

intermediate

  • Why are cgroups critical to cloud computing providers like AWS?

Flash Cards

Question

Exceed memory limit?

Click to reveal answer
Answer

The Linux Kernel's OOM (Out Of Memory) Killer will instantly terminate the process to protect the rest of the system.

Question

Why critical to AWS?

Click to reveal answer
Answer

Cgroups allow cloud providers to safely sell 'slices' of a massive server to multiple customers. Cgroups guarantee that Customer A's code cannot hog the CPU and slow down Customer B's code on the same physical machine.