Fork
examples/other/show-forking/Cargo.toml
[package] name = "show-forking" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] fork = "0.1.22"
examples/other/show-forking/src/main.rs
use fork::{fork, Fork}; fn main() { println!("Before {}", std::process::id()); match fork() { Ok(Fork::Parent(child)) => { println!( "In parent process {}, new child has pid: {}", std::process::id(), child ); } Ok(Fork::Child) => { println!("In child process {}", std::process::id()); std::process::exit(0); } Err(_) => println!("Fork failed"), } println!("Launched {}", std::process::id()); println!("After {}", std::process::id()); }
TODO: wait, waitpid?