nix::unistd

Function daemon

source
pub fn daemon(nochdir: bool, noclose: bool) -> Result<()>
Expand description

Daemonize this process by detaching from the controlling terminal (see daemon(3)).

When a process is launched it is typically associated with a parent and it, in turn, by its controlling terminal/process. In order for a process to run in the “background” it must daemonize itself by detaching itself. Under posix, this is done by doing the following:

  1. Parent process (this one) forks
  2. Parent process exits
  3. Child process continues to run.

nochdir:

  • nochdir = true: The current working directory after daemonizing will be the current working directory.
  • nochdir = false: The current working directory after daemonizing will be the root direcory, /.

noclose:

  • noclose = true: The process’ current stdin, stdout, and stderr file descriptors will remain identical after daemonizing.
  • noclose = false: The process’ stdin, stdout, and stderr will point to /dev/null after daemonizing.