[][src]Function fork::daemon

pub fn daemon(nochdir: bool, noclose: bool) -> Result<Fork, i32>

The daemon function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons.

  • nochdir = false, changes the current working directory to the root (/).
  • noclose = false, will close standard input, standard output, and standard error

Errors

If an error occurs, returns -1

Example:

use fork::{daemon, Fork};
use std::process::Command;

if let Ok(Fork::Child) = daemon(false, false) {
    Command::new("sleep")
        .arg("3")
        .output()
        .expect("failed to execute process");
}