[−][src]Function fork::fork
pub fn fork() -> Result<Fork, i32>
Create a new child process see fork(2)
Upon successful completion, fork() returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created.
Example:
use fork::{fork, Fork}; match fork() { Ok(Fork::Parent(child)) => { println!("Continuing execution in parent process, new child has pid: {}", child); } Ok(Fork::Child) => println!("I'm a new child process"), Err(_) => println!("Fork failed"), }
This will print something like the following (order indeterministic).
Continuing execution in parent process, new child has pid: 1234
I'm a new child process
The thing to note is that you end up with two processes continuing execution immediately after the fork call but with different match arms.
nix::unistd::fork
The example has been taken from the nix::unistd::fork
,
please check the Safety section
Errors
returns -1
if error