In this basic challenge, you will need to start a Linux process while limiting its CPU and memory usage.
The binary you will run is called omnihog
,
a simple resource hog program that consumes all available CPU and memory resources when started.
Run it in a cgroup with a CPU limit of 10% and a memory limit of 500 MB.
Good luck!
Hint 1 π‘
If you've never worked with cgroups before, check out this step-by-step guide - Controlling process resources with Linux cgroups.
![Linux control group v2 visualized.](/content/files/challenges/limit-cpu-and-memory-of-linux-process/__static__/cgroup-v2-rev2.png)
Hint 2 π‘
There are many ways to configure cgroups - you can manipulate the cgroupfs directly,
use libcgroup's cgcreate
, cgexec
and the like tools,
or go full-on with systemd.
Either of these methods is well-suited for this challenge.
Hint 3 π‘
If you decided to configure the cgroup manually and getting the Permission denied
error when trying to write to the cpu.max
or memory.max
files,
make sure the cpu
and memory
controllers are enabled for the cgroup.
Are they mentioned in the /sys/fs/cgroup/<your-cgroup>/cgroup.controllers
file?
Hint 4 π‘
To enable the cpu
and memory
controllers for the given cgroup,
you need to write +cpu +memory
to the parent cgroup's cgroup.subtree_control
file π€―
Hint 5 π‘
While cgroups are hierarchical creatures, and parent's cgroup settings are inherited by child cgroups,
due to the limitations of the solution checker, you'll need to configure the omnihog
's own cgroup
(or the closest systemd slice if you decided to follow systemd-run --slice ...
path).