How to do it...

The following steps will walk you through the recipe:

  1. Create a file named sample_wait.rs and open it in your text editor.
  2. Write the code header with the relevant information:
        //-- #########################
//-- Task: Waiting for a child process
//-- Author: Vigneshwer.D
//-- Version: 1.0.0
//-- Date: 19 March 17
//-- #########################
  1. Call the standard library:
        // Calling the standard libraries
use std::process::Command;
  1. Define the main function and create a child process using the Command struct:
        // Main execution starts here
fn main() {
// Creating a child process
let mut child =
Command::new("sleep").arg("5").spawn().unwrap();
  1. Create a variable named _result and call the wait method, the last print statement, marking the end of the program:
        // Waiting for the child process to complete
let _result = child.wait().unwrap();

// printing the status of child process
print!("Status if child process {} ", _result);
// Marking the end of the main function
println!("reached end of main");
}

You will get the following output upon successful execution of the code:



..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.151.44