# Linux Control Groups (cgroups)

> A Linux limit on memory and CPU. Each box gets its own cap.

**Field:** Infrastructure  
**Category:** Containers  
**Also known as:** cgroups, cgroup, cgroups v2, Control Groups (Linux)

## Think of it like

Think of it like giving each child a set number of sweets. When they run out, they have to wait.

## Definition

Control groups are a Linux feature that limits how much a group of programs may use. A cgroup can cap memory, CPU time and disk reads and writes. It also counts what the group is using, which is how tools show a container's usage. When a container goes over its memory cap, Linux stops a program inside it. Containers use cgroups so that one cannot starve the rest.

## Example

Jack starts a container with a 512 MB memory cap. When his app grows past it, Linux stops the app instead of letting it slow the whole server.

## Example code

```bash
docker run -d --memory=512m --cpus=1.5 nginx
```

These flags set a cap on memory and CPU for this one box. Linux keeps the cap.

## Why it matters

With no limits, one busy box can take all the memory. Then every other program on the server slows down.

## Common mistake

Setting no memory limit and trusting the app. A leak then grows until the whole machine runs short.

## Three principles

- **Caps use.** Memory, CPU and disk can be limited.
- **Counts use.** Tools read a container's numbers from it.
- **Over the cap.** A program past its memory cap is stopped.

## Related terms

- [Container](https://learn.benibix.com/term/infrastructure/container)
- [Linux Namespace](https://learn.benibix.com/term/infrastructure/linux-namespace)
- [Container Runtime](https://learn.benibix.com/term/infrastructure/container-runtime)
- [Random Access Memory (RAM)](https://learn.benibix.com/term/infrastructure/random-access-memory)
- [Kernel](https://learn.benibix.com/term/development/kernel)
- [Noisy Neighbor](https://learn.benibix.com/term/infrastructure/noisy-neighbor)

![One host with a shared kernel bar along the bottom. Two containers sit on it, each with its own process list, network and files drawn inside. A dashed fence around each container is labelled with a memory and CPU limit.](https://learn.benibix.com/diagrams/inf4-container-isolation.svg)

---

Source: https://learn.benibix.com/term/infrastructure/control-groups
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
