Forks the process and executes a function in the child process.
fn fork<F>(f: F) -> Result<i32, Errno>
where F: FnOnce() -> (),| Name | Description |
|---|---|
| f | The function that will be executed in the child process. |
Returns the process id of the child process.
The function f will only be executed in the child process. When the function returns, the child process automatically exits with exit code 0.
let res = fork(|| println!("I'm in the child process"));
match res {
Some(n) => println!("Executed the child process: {}", n),
Err(e) => println!("Could not execute the child process: {:?}", e),
}