pub fn waitpid(pid: i32) -> Result<(), i32>Expand description
Wait for process to change status see wait(2)
ยงErrors
returns -1 if error
Example:
use fork::{waitpid, Fork};
use std::process::Command;
fn main() {
match fork::fork() {
Ok(Fork::Parent(pid)) => {
println!("Child pid: {pid}");
match waitpid(pid) {
Ok(_) => println!("Child existed"),
Err(_) => eprintln!("Failted to wait on child"),
}
}
Ok(Fork::Child) => {
Command::new("sleep")
.arg("1")
.output()
.expect("failed to execute process");
}
Err(_) => eprintln!("Failed to fork"),
}
}