You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
653 B
Rust

extern crate nix;
use nix::unistd::{fork,ForkResult};
use std::{thread,time};
use std::process;
fn main() {
let mut children = Vec::new();
for _ in 0..3 {
match fork().expect("fork failed") {
ForkResult::Parent{ child: pid } => { children.push(pid); }
ForkResult::Child => {
let t = time::Duration::from_millis(1000);
loop {
println!("child process #{}", process::id());
thread::sleep(t);
}
}
}
}
let t = time::Duration::from_millis(1000);
loop {
println!("parent process #{}", process::id());
thread::sleep(t);
}
}