通过例子学习Rust

47.2 等待

When a Process goes out of scope, its drop method will wait until the child process finishes before releasing the resource.

// wait.rs
use std::io::process::Command;

fn main() {
    let _process = Command::new("sleep").arg("5").spawn();

    println!("reached end of main");
}
$ rustc wait.rs && ./wait
reached end of main
# `wait` keeps running for 5 seconds
# `sleep 5` command ends, and then our `wait` program finishes