All of lore.kernel.org
 help / color / mirror / Atom feed
* Wrapper to run a command in a temporary cgroup
@ 2022-04-04 12:25 R. Diez
       [not found] ` <0174490d-8679-3885-df31-e9f6c1e7205b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: R. Diez @ 2022-04-04 12:25 UTC (permalink / raw)
  To: cgroups mailinglist

Hi all:

I am looking for a wrapper script like this:

run-on-temporary-cgroup.sh cmd arg1 ... argn.

The tool should create a temporary cgroup, run the process inside, and return the same exit code as the user command.

I may want to limit the amount of memory the cgroup is allowed to consume. But more importantly, I want the tool to return when all processes in the cgroup (the user command an any children) have already terminated. This is apparently not so easy to achieve without cgroups.

Those requirements are similar to what systemd-run does, but I need an alternative which does not depend on systemd.

Even if you have systemd, systemd-run is rather convenient, but it is somewhat heavy weight and it has issues with some signals (like SIGTERM), and with escaping/quoting, depending on the mode (--scope vs --wait).

If there is no such a tool, can someone give me some hints on how to implement one? Is it possible in Shell or Perl? Or do I need to reach to C / C++? Is there anything similar I could take as basis?

Apologies if this is not the right mailing list. I could not find anywhere else to ask about cgroups matters.

Regards,
   rdiez

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Wrapper to run a command in a temporary cgroup
       [not found] ` <0174490d-8679-3885-df31-e9f6c1e7205b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2022-04-05 11:27   ` Michal Koutný
  0 siblings, 0 replies; 2+ messages in thread
From: Michal Koutný @ 2022-04-05 11:27 UTC (permalink / raw)
  To: R. Diez; +Cc: cgroups mailinglist

Hello.

On Mon, Apr 04, 2022 at 02:25:27PM +0200, "R. Diez" <rdiez1999-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> run-on-temporary-cgroup.sh cmd arg1 ... argn.
> 
> The tool should create a temporary cgroup, run the process inside, and
> return the same exit code as the user command.

This sounds very much like `systemd-run --scope`.

> Those requirements are similar to what systemd-run does, but I need an
> alternative which does not depend on systemd.

Fair enough.

> Even if you have systemd, systemd-run is rather convenient, but it is
> somewhat heavy weight 

Then a suggestion of using a container runtime is likely out of question
too.

> If there is no such a tool, can someone give me some hints on how to
> implement one? Is it possible in Shell or Perl? Or do I need to reach
> to C / C++? Is there anything similar I could take as basis?

There's also libcg [1] (whose cgroup v2 support is WIP AFAIK) with its
cgexec utility. I don't know other tools (besides the named previously).

You can implement it in whatever environment that can interact with
filesystem (and perhaps poll for events), it's all documented in [2]
(alternatively [3], which I'd discourage for a new project).

HTH,
Michal

[1] https://github.com/libcgroup/libcgroup/blob/main/README
[2] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html
[3] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/cgroups.html


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-05 11:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 12:25 Wrapper to run a command in a temporary cgroup R. Diez
     [not found] ` <0174490d-8679-3885-df31-e9f6c1e7205b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2022-04-05 11:27   ` Michal Koutný

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.