Reputation: 2512
I am using cgroup v2, and I want to create a new cgroup and let an existing process use that cgroup. I did the following but not successful. What is wrong here?
$ cd /sys/fs/cgroup
$ sudo mkdir g1
$ sudo chown -R name.name g1 # name is the user name
$ echo 4000 | tee g1/cgroup.procs
tee: cgroup.procs: Permission denied
$ echo 4000 | sudo tee g1/cgroup.procs
# this works
Why can't I write to cgroup.procs
even I am the owner of all the controller interface?
Upvotes: 2
Views: 2033
Reputation: 92627
This caught me out as well. A rule of cgroup v2 is that in order to move a pid from a source to a target group, the current user must have write permissions to the common ancestor of source and target. Your echo command is likely running in a user.slice, which you can verify if you check the cgroup of your current shell:
cat /proc/self/cgroup
# 0::/user.slice/user-1234.slice/session-5124.scope
That means the common ancestor group is "/". The reason the sudo works is because it is running as root to write the pid, which has permissions to /sys/fs/cgroup/cgroup.procs
And therefore, in order for your current user to have the same capability, you would need write permissions opened up to /sys/fs/cgroup/cgroup.procs
, which I know, kind of sucks.
Upvotes: 1