If you have recent enough Linux distribution you should be able to run processes in transient (temporary) cgroups, e.g.
$ systemd-run --user --scope /bin/bash
However, systemd
is broken in many Linux distributions Ubuntu versions prior 21.10 and that fails with something like
polkitd(authority=local)[1300]: Registered Authentication Agent for unix-process:10428:26722972 (system bus name :1.478 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_DK.utf8)
systemd[2601]: run-rbe547d13ad2c41d7857ea9e660e51ab9.scope: Failed to add PIDs to scope's control group: Permission denied
systemd[2601]: run-rbe547d13ad2c41d7857ea9e660e51ab9.scope: Failed with result 'resources'.
systemd[2601]: Failed to start /bin/bash.
polkitd(authority=local)[1300]: Unregistered Authentication Agent for unix-process:10428:26722972 (system bus name :1.478, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_DK.utf8) (disconnected from bus)
The reason for this failure is that running transient cgroups without root requires support for cgroupv2
but Canonical really wants to push snap
and using cgroupv2
would have broken snap
until the snap
had been patch enough. Ubuntu 21.10 is the first Ubuntu release that has smart enough snap
to work with cgroupv2
so any older Ubuntu version is intentionally broken for transient cgroups to allow snap
to run at all.
I guess distributions that do not even try to support the misfeature called snap
will have much less problems supporting cgroupv2
and this should work with older distribution versions, too.