def StartDaemon(self):
    # To spin off the process, use what seems to be the "standard" way to spin
    # off daemons: fork a child process, make it the session and process group
    # leader, then fork it again so that the actual daemon process is no longer
    # a session leader.
    #
    # This is a very simplified (with significantly reduced features) version of
    # the python-daemon library at https://pypi.python.org/pypi/python-daemon/.
    pid = os.fork()
    logging.debug('Forked new process, pid= {0}'.format(pid))
    if pid == 0:
      os.setsid()
      pid = os.fork()
      if pid == 0:
        os.chdir('/')
        os.umask(0)
      else:
        # The use of os._exit here is recommended for parents of a daemon
        # process to avoid issues with running the cleanup tasks that
        # sys.exit() runs by preventing issues from the cleanup being run
        # more than once when the two parents exit and later when the daemon
        # exits.
        os._exit(0)
    else:
      os._exit(0)

    # Set up pidfile and signal handlers.
    pidf = open(self.pidfile, 'w')
    pidf.write(str(os.getpid()))
    pidf.close()

    logging.debug('Sending signal SIGTERM to shutdown daemon')
    signal.signal(signal.SIGTERM, self.ShutdownDaemon)

    self.accounts_manager.Main()
Spins off a process that runs as a daemon.
dataset/ETHPy150Open GoogleCloudPlatform/compute-image-packages/google-daemon/usr/share/google/google_daemon/accounts_manager_daemon.py/AccountsManagerDaemon.StartDaemon