Challenge, Easy,  on  Linux

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.
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).

Categories: Linux
Tags:  #cgroups
Discussion:  Discord

Level up your Server Side game — Join 9,000 engineers who receive insightful learning materials straight to their inbox