Control how the kernel divides CPU time between groups of processes using cgroups so one workload cannot starve another. 01.01.2026 | reading time: 3 min Want background jobs to yield CPU to interactive servers without hard limits? This short guide shows how to set relative CPU weights with cgroups so workloads share the CPU in a predictable ratio. A reproducible scenario Imagine a single host running a web worker and a heavy batch job; the web worker must stay responsive while the batch job uses spare cycles; the goal is to give the web worker higher CPU weight and keep the batch job constrained by relative shares. Hands-on: create two groups and run ```bash # create two cgroups (cgroup v1 example) sudo mkdir -p /sys/fs/cgroup/cpu/low && sudo mkdir -p /sys/fs/cgroup/cpu/high echo 512 | sudo tee /sys/fs/cgroup/cpu/low/cpu.shares echo 2048 | sudo tee /sys/fs/cgroup/cpu/high/cpu.shares # start two simple CPU hogs yes > /dev/null & LOW_PID=$! yes > /dev/null & HIGH_PID=$! # move processes into groups echo $LOW_PID | sudo tee /sys/fs/cgroup/cpu/low/tasks echo $HIGH_PID | sudo tee /sys/fs/cgroup/cpu/high/tasks # observe approximate CPU split (example output shown) top -b -n2 -p $LOW_PID,$HIGH_PID | sed -n '7,8p' # expected sample lines: # PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND # 12345 user 20 0 0 0 0 R 20.0 0.0 0:10.00 yes # 12346 user 20 0 0 0 0 R 5.0 0.0 0:02.50 yes # cleanup (kill jobs and remove groups) sudo kill $LOW_PID $HIGH_PID || true sudo rmdir /sys/fs/cgroup/cpu/low /sys/fs/cgroup/cpu/high ``` Key knobs and when to use them cpu.shares is a relative weight (default 1024) and does not cap CPU; use cpu.cfs_quota_us and cpu.cfs_period_us for absolute limits on cgroup v1, or cpu.max on cgroup v2; systemd exposes these via CPUWeight or CPUQuota for services, and containers commonly rely on cgroups under the hood; root privileges are required to create or populate cgroups when not managed by systemd. Other integrations to know If your distro uses cgroup v2 the equivalent is cpu.weight with a different scale, and you can use systemd-run --scope -p CPUWeight= to create scoped slices; the libcgroup utilities (cgcreate, cgset) simplify cgroup v1 management, and orchestration systems and container engines provide higher-level controls that map to these kernel interfaces. Wrap-up and next steps Relative CPU shares are a light, effective tool to prioritize workloads without hard throttling; experiment on a nonproduction host, compare behavior under load, and then consider reading cgroup v2 docs and systemd resource controls to broaden your toolbox; deepen Linux skills and aim for certifications like CompTIA Linux+ or LPIC-1 with focused exam preparation at bitsandbytes.academy. Join Bits & Bytes Academy First class LINUX exam preparation. processes infrastructure scripting troubleshooting