Last active
January 25, 2024 01:47
-
-
Save dulimarta/46f3f57bc33ca2dacc030025dc7675b0 to your computer and use it in GitHub Desktop.
CS452 Lab02 - Sample 2 (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 std::env; | |
use nix::unistd::fork; | |
use std::process; | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
if args.len() < 2 { | |
eprintln!("Not enough argument"); | |
return; | |
} | |
let limit = args[1].parse::<u32>(); | |
if let Ok(n) = limit { | |
let _ = fork(); | |
let _ = fork(); | |
let who = process::id(); | |
for n in 0..n { | |
println!("PID: {} {}", who, n); | |
} | |
} else { | |
eprintln!("Input {} is not an integer", args[1]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment