Function lrs::process::fork

Forks the process and executes a function in the child process.

Syntax

fn fork<F>(f: F) -> Result<i32, Errno>
    where F: FnOnce() -> (),

Arguments

NameDescription
f

The function that will be executed in the child process.

Return value

Returns the process id of the child process.

Remarks

The function f will only be executed in the child process. When the function returns, the child process automatically exits with exit code 0.

Examples

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),
}

See also