Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to be able to create a one-time temporary group in hierarchy. For example:

run_with_csubgroup /sys/fs/cgroup/group/subgroup/

Which creates group say /sys/fs/cgroup/group/subgroup/5G7ds/ (5G7ds is one-time name - it might be ID or anything).

I would like to delete the group automatically but I don't know how to do it easily and prone to say TERM signal (from actidental C-c).

Is there a way to do it? I'm using Gentoo+systemd.

share|improve this question
Are you sure you really need to create a temporary group? –  tiktak Mar 28 '12 at 12:17
@Mathieu: I don't need to create a temporary group but I have a set of tasks which contains various processes (each takes a few minutes to few hours). I want (not need) them to compete in scheduler as a whole rather then as separate processes. –  Maciej Piechotka Mar 28 '12 at 15:48
You can use trap to react on signals. Does not solve the question re. cgroups but may help re. capturing ctrl-c –  Ulrich Dangel Jun 11 '12 at 21:09

3 Answers 3

You may need to specify a specific lifetime for your group; you may want it on after computer startup and deleted after shutdown. So it's not a bad idea to add it to your /etc/rc scripts .

share|improve this answer

You can run your command(s) via systemd-run --scope. This creates a transient (ie temporary) cgroup for your command. You can then modify the cgroup to your needs. Use systemd-cgls to find your process in the cgroup hierarchy under /sys/fs/cgroup.

According to the systemd-run manpage

systemd-run may be used to create and start a transient .service or a transient .timer or a .scope unit and run the specified COMMAND in it.

You can also specify restrictions for your unit via the systemd-run command by using the --property flag (more than once is allowed). For available properties you can check with the sytemd.resource-control manpage.

If you want to set properties later on, you can use systemd set-property.

Keep in mind that it's a good idea to provide a name for your unit with the --unit=yourname flag, so you can easily access it.

There is a very good text about the new control group interface, which I strongly recommend. Also, the Red Hat Enterprise Linux 7 Resource Management and Linux Containers Guide provides a very clear description of how to use cgroups wirh systemd.

share|improve this answer
If it's about the links: I couldn't add more than two links yet :-) –  Julius Blank Jun 13 at 5:47
In case I got somerhing wrong, I apologize! –  Julius Blank Jun 13 at 5:48
Added the links :-) –  Julius Blank Jun 13 at 6:22

Not sure I understand correctly, but can't you just:

~] umount /sys/fs/cgroup/group/subgroup/5G7ds/
~] rmdir /sys/fs/cgroup/group/subgroup/5G7ds/

The above unmounts the cgroup and removes it.

share|improve this answer
I would like to have it automated. I.e. a group which 'autodestructs' when there is no tasks to it (in similar way as inode is freed after there is no entries pointing to it). –  Maciej Piechotka May 16 '12 at 6:28
The easiest solution that comes to mind is just checking whether a tasks file in a given cgroup is empty and if it is, run the above commands. You can set it up as a cron job that executes every 10 minutes and cleans up any "unused" cgroups. –  mart1n Jun 5 '12 at 17:30

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.