Skip to content

Instantly share code, notes, and snippets.

@dulimarta
Created January 25, 2024 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dulimarta/7ceb8352d72e616c722eb5f1bf9dce16 to your computer and use it in GitHub Desktop.
Save dulimarta/7ceb8352d72e616c722eb5f1bf9dce16 to your computer and use it in GitHub Desktop.
CS452 Lab02 - Sample 3 (Rust)
use nix::unistd::{fork, ForkResult};
// use nix::sys::wait::wait;
// use nix::sys::wait::WaitStatus;
use std::process;
fn main() {
let pid = fork();
match pid {
Ok(ForkResult::Child) => {
println!("I'm a child with PID {}", process::id());
/* Insert an appropriate call to exit() here */
}
Ok(ForkResult::Parent { child: _ }) => {
println!("I'm the parent with PID {}", process::id());
/* Insert an appropriate form of wait() call here */
}
Err(_) => {
eprintln!("Fork failure");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment