Comments (5)
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.
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.
@levex I would love to use the new API. Are there any roadblocks? Can I help with sorting them out?
from cgroups-rs.
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.
@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
withoutV1
, 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cgroups-rs.