Created
January 25, 2024 02:00
-
-
Save dulimarta/7ceb8352d72e616c722eb5f1bf9dce16 to your computer and use it in GitHub Desktop.
CS452 Lab02 - Sample 3 (Rust)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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