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.
trap
to react on signals. Does not solve the question re. cgroups but may help re. capturingctrl-c
– Ulrich Dangel Jun 11 '12 at 21:09