Files
sausage/userland/procps/src/main.rs
T

32 lines
991 B
Rust

//! ps reads the process snapshot. kill stops a process group through the process interface.
mod bindings {
wit_bindgen::generate!({ path: "../../host/wit", world: "program", generate_all });
}
fn main() {
let args: Vec<String> = std::env::args().collect();
match std::path::Path::new(&args[0])
.file_stem()
.unwrap()
.to_str()
.unwrap()
{
"ps" => print!(
"{}",
std::fs::read_to_string("/proc/processes").expect("process snapshot")
),
"kill" => {
if args.len() < 2 {
std::process::exit(2);
}
for pid in &args[1..] {
let pid: u32 = pid.parse().expect("numeric pid");
if let Err(error) = bindings::sausage::process::host::kill(pid) {
eprintln!("kill: {error}");
std::process::exit(1);
}
}
}
_ => std::process::exit(127),
}
}