Skip to main content

Module fork

Module fork 

Source
Expand description

Unix double-fork into background for daemon process isolation.

The double-fork pattern detaches the daemon from the calling terminal:

  1. First fork: parent exits (shell regains control).
  2. setsid(): grandchild becomes session leader (no controlling TTY).
  3. Second fork: ensure the daemon can never reacquire a TTY.
  4. Redirect stdin/stdout/stderr to the daemon log file.

Functions§

double_fork_into_background
Double-fork into background and redirect stdio to log_path.