Fork: Difference between revisions

710 bytes added ,  4 years ago
Add rust example (tested on linux/OS X)
(Add rust example (tested on linux/OS X))
Line 1,300:
#handle DisplayBanner("Welcome!")</lang>
 
=={{header|Rust}}==
This uses the nix(0.15) crate. The code has been tested on Linux, OS X.
{{libheader|nix}}<lang rust>use nix::unistd::{fork, ForkResult};
use std::process::id;
 
fn main() {
match fork() {
Ok(ForkResult::Parent { child, .. }) => {
println!(
"This is the original process(pid: {}). New child has pid: {}",
id(),
child
);
}
Ok(ForkResult::Child) => println!("This is the new process(pid: {}).", id()),
Err(_) => println!("Something went wrong."),
}
}
</lang>output<lang>This is the original process(pid: 88637). New child has pid: 88651
This is the new process(pid: 88651).
</lang>
=={{header|Scala}}==
{{libheader|Scala}}
Anonymous user