I'm trying to limit the CPU usage of a process using cgroups v2. The hierarchy is already created and the limits are set, I just need to write the pid into the cgroup.procs file. The path is /sys/fs/cgroup/system.slice/myfolder/myfolder/myfolder/cgroup.procs. All the myfolders' permissions are drwxr-xr-x myuser mygroup. The permissions of the cgroup.procs file are -rwxrwxrwx myuser mygroup. Yet, when trying to execute the following command:

sudo -H -u myuser bash -c 'echo some_existing_pid > /sys/fs/cgroup/system.slice/myfolder/myfolder/myfolder/cgroup.procs'

I get the following error:

bash: line 1: echo: write error: Permission denied

What can be a possible reason for that?

OS: Ubuntu 22.04

1 Answer 1


My first guess is that you're not allowed to move processes out of their original cgroup. The rule used by the kernel is that in order to migrate a process from cgroup A to cgroup B, you must first have permissions to migrate it to the cgroup that is the common ancestor of both A and B.

(I would probably recommend using systemd built-in cgroup hierarchy management, i.e. creating .slice units to define hierarchy and then moving processes into .scope units via systemd-run.)

  • The process I'm trying to move doesn't belong to any cgroup. I basically tried to do the following: nc -l 5000 & and then used the pid in the command in question. It failed as well with the same error
    – zlatonick
    Mar 8 at 14:44
  • "doesn't belong to any cgroup" is a very unlikely state – as long as cgroups are enabled, every process is automatically participating; even if the process is in the root / cgroup, it's still in a cgroup. (Even more so in cgroups v2, where only leaf cgroups can contain processes, so there's no way for a process to be in the root cgroup either.) Mar 8 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .