Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create and use cgroups as a non-root user?

For example, can I, entirely as a non-root user:

  • create a cgroup with access to one CPU
  • create a new process in that cgroup


I first asked here but I didn't receive a complete answer. I also asked on stackoverflow, but the question was closed as off topic.

share|improve this question
up vote 9 down vote accepted

You can't do that as a normal user. But you can setup a cgroup as root, and make it configurable by your user.

If you do not already have the default cgroups controllers mounted by e.g. systemd:

$ sudo mount -t tmpfs cgroup_root /sys/fs/cgroup
$ sudo mkdir /sys/fs/cgroup/cpuset
$ sudo mount -t cgroup -o cpuset cpuset /sys/fs/cgroup/cpuset

Create a cgroup:

$ sudo mkdir /sys/fs/cgroup/cpuset/${USER}
$ sudo chown -R ${USER} /sys/fs/cgroup/cpuset/${USER}

You can now modify the configuration of your cgroup as a normal user:

$ echo 0-3 > /sys/fs/cgroup/cpuset/${USER}/cpuset.cpus

Add a process to that group:

$ ./my_task &
$ echo $! > /sys/fs/cgroup/cpuset/${USER}/tasks

Or create a subgroup:

$ mkdir /sys/fs/cgroup/cpuset/${USER}/subgroup
$ echo 0-1 > /sys/fs/cgroup/cpuset/${USER}/subgroup/cpuset.cpus
$ ./my_other_task &
$ echo $! > /sys/fs/cgroup/cpuset/${USER}/subgroup/tasks
share|improve this answer
how would you delete the subgroup? rm -r fails for me – hbogert Jun 11 at 15:34
rm -r would try to delete the files first, which fails. Use rmdir to remove a cgroup. – Dennis B. Jun 12 at 15:59

If you're using Ubuntu you (the root user) can install cgroup-lite and add what you need to /etc/cgconfig.conf, including which user(s) can change the cgroup's configuration. It runs on boot.

Failing that you (the root user) could add your own script to run during boot.

share|improve this answer

There is a series of articles on LWN on cgroups, see part 1, or look though the search there. Systemd includes a set of helpers to manage (processes caged by) cgroups.

share|improve this answer
That link for part 1 should probably point to instead. – chris Jul 12 '13 at 9:31
The linked LWN article is about namespaces, is about cgroups. – Dennis B. Jun 12 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.