Function daemonize_redirect

Source
pub fn daemonize_redirect<PO, PE>(
    stdout: Option<PO>,
    stderr: Option<PE>,
    chdir: ChdirMode,
) -> Result<pid_t, Error>
where PO: AsRef<Path>, PE: AsRef<Path>,
Expand description

Performs program daemonizing with optional redirection for STDIN and STDOUT. If the redirection parameter is None, then stream will be redirected to /dev/null, otherwise it will be redirected to the file provided.

Returns the new process id after all forks.

Examples found in repository?
examples/simple_daemon.rs (line 12)
7fn main() {
8    let mut args = env::args();
9    let cmd_proc = args.next().unwrap();
10    if let (Some(stdout_filename), Some(stderr_filename)) = (args.next(), args.next()) {
11        println!("Ready to daemonize, target stdout_filename = {}, stderr_filename = {}", stdout_filename, stderr_filename);
12        daemonize_redirect(Some(stdout_filename), Some(stderr_filename), ChdirMode::ChdirRoot).unwrap();
13        for _ in 0 .. 10 {
14            println!("A string for stdout!");
15            writeln!(&mut io::stdout(), "Another string for stdout!").unwrap();
16            writeln!(&mut io::stderr(), "A string for stderr!").unwrap();
17            thread::sleep(time::Duration::from_millis(1000));
18        }
19        println!("Successfull termination");
20        panic!("An now a panic occurs!");
21    } else {
22        writeln!(&mut io::stderr(), "Usage: {} <stdout_filename> <stderr_filename>", cmd_proc).unwrap();
23        process::exit(1);
24    }
25}