GithubHelp home page GithubHelp logo

Comments (5)

tecywiz121 avatar tecywiz121 commented on July 29, 2024

It does look a lot cleaner! One thing I've noticed about the current API is that if you only set up memory, but you try to add a PID to the Cgroup, it'll attempt to add to all types of cgroup, even the ones you haven't setup yet, which often fails. I think setting it up this way will be more intuitive!

You'll need a function for moving the current process into a cgroup as well.

I'd do something like this for spawning commands:

use std::process::Command;
use std::os::unix::process::CommandExt;

pub trait ComandCgroup {
    fn cgroup(&mut self, &Cgroup) -> &mut Self;
}

impl CommandCgroup for Command {
    fn cgroup(&mut self, cgroup: &Cgroup) -> &mut Self {
        self.before_exec(|| {
            unimplemented!()
        })
    }
}

from cgroups-rs.

levex avatar levex commented on July 29, 2024

Yeah, lazily creating the controllers is on my TODO list (which I really really should convert into Issues here).

Your suggestion for the trait seems great, I'll add that.

BTW, the current state-of-the-art for the builder pattern is on builder-pattern branch of this repo.

from cgroups-rs.

frol avatar frol commented on July 29, 2024

@levex I would love to use the new API. Are there any roadblocks? Can I help with sorting them out?

from cgroups-rs.

levex avatar levex commented on July 29, 2024

Hi @frol, great! No there aren't any. I just need to make a cargo release. I'll make one tomorrow, as I'm unable to do that from this machine.

from cgroups-rs.

frol avatar frol commented on July 29, 2024

@levex I want to let you know that I ended up implementing my own cgroups-fs crate due to the following issues:

  • I could not attach a child process to the cgroup (you cannot move Cgroup without V1, and I don't actually want to move, but .before_exec captures them).
  • This crate parses/touches too many control files while I only need a few.

Here is what I, essentially, wanted (and built):

let my_cgroup = cgroups_fs::CgroupName::new("my-cgroup");
let my_memory_cgroup = cgroups_fs::AutomanagedCgroup::init(&my_cgroup, "memory").unwrap();

use cgroups_fs::CgroupsCommandExt;
let output = std::process::Command::new("echo")
    .arg("Hello world")
    .cgroups(&[&my_memory_cgroup])
    .output()
    .expect("Failed to execute command");

println!(
    "The echo process used {} bytes of RAM.",
    my_memory_cgroup.get_value::<u64>("memory.max_usage_in_bytes").unwrap()
);

from cgroups-rs.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.