src/utils/process.cpp
/**
   * Forks a child process and completely detaches it.
   *
   * In the child process, the given lambda function is executed.
   * We fork twice so that the first forked process can exit and it's child is
   * reparented to the init process.
   *
   * Ref: https://web.archive.org/web/20120914180018/http://www.steve.org.uk/Reference/Unix/faq_2.html#SEC16
   *
   * Use this if you want to run a command and just forget about it.
   *
   * \returns The PID of the child process
   */
Forks a child process and completely detaches it.
In the child process, the given lambda function is executed.
We fork twice so that the first forked process can exit and it's child is
reparented to the init process.



Use this if you want to run a command and just forget about it.

\returns The PID of the child process
Forks a child process and completely detaches it . In the child process the given lambda function is executed . We fork twice so that the first forked process can exit and it ' s child is reparented to the init process . Use this if you want to run a command and just forget about it . \ returns The PID of the child process
void fork_detached(std::function<void()> const& lambda) {
    pid_t pid = fork();
    switch (pid) {
      case -1:
        throw runtime_error("fork_detached: Unable to fork: " + string(strerror(errno)));
      case 0:
        setsid();
        pid = fork();
        switch (pid) {
          case -1:
            throw runtime_error("fork_detached: Unable to fork: " + string(strerror(errno)));
          case 0:
            umask(0);
            redirect_stdio_to_dev_null();
            lambda();
            _Exit(0);
        }
        _Exit(0);
      default:
        wait(pid);
    }
  }
void fork_detached ( std :: function < void ( ) > const & lambda ) { pid_t pid = fork ( ) ; switch ( pid ) { case -1 : throw runtime_error ( " " + string ( strerror ( errno ) ) ) ; case 0 : setsid ( ) ; pid = fork ( ) ; switch ( pid ) { case -1 : throw runtime_error ( " " + string ( strerror ( errno ) ) ) ; case 0 : umask ( 0 ) ; redirect_stdio_to_dev_null ( ) ; lambda ( ) ; _Exit ( 0 ) ; } _Exit ( 0 ) ; default : wait ( pid ) ; } }
Forks a child process and completely detaches it.
Forks a child process and completely detaches it .
// Child // Child /*
         * The first fork immediately exits and we have to collect its exit
         * status
         */