docs: def minion_process():
      '''
      Start a minion process
      '''
      import salt.utils.platform
      import salt.utils.process
      import salt.cli.daemons
  
      # salt_minion spawns this function in a new process
  
      salt.utils.process.appendproctitle('KeepAlive')
  
      def handle_hup(manager, sig, frame):
          manager.minion.reload()
  
      lock = threading.RLock()
  
      def suicide_when_without_parent(parent_pid):
          '''
          Have the minion suicide if the parent process is gone
  
          NOTE: small race issue where the parent PID could be replace
          with another process with same PID!
          '''
          while lock.acquire(blocking=False):
              lock.release()
              time.sleep(5)
              try:
                  # check pid alive (Unix only trick!)
                  if os.getuid() == 0 and not salt.utils.platform.is_windows():
                      os.kill(parent_pid, 0)
              except OSError as exc:
                  # forcibly exit, regular sys.exit raises an exception-- which
                  # isn't sufficient in a thread
                  log.error('Minion process encountered exception: %s', exc)
                  os._exit(salt.defaults.exitcodes.EX_GENERIC)
  
      try:
          if not salt.utils.platform.is_windows():
              thread = threading.Thread(target=suicide_when_without_parent, args=(os.getppid(),))
              thread.start()
  
          minion = salt.cli.daemons.Minion()
          signal.signal(signal.SIGHUP,
                        functools.partial(handle_hup,
                                          minion))
          minion.start()
      except (SaltClientError, SaltReqTimeoutError, SaltSystemExit) as exc:
          lock.acquire(blocking=True)
          log.warning('Fatal functionality error caught by minion handler:\n', exc_info=True)
          log.warning('** Restarting minion **')
          delay = 60
          if minion is not None and hasattr(minion, 'config'):
              delay = minion.config.get('random_reauth_delay', 60)
          delay = randint(1, delay)
          log.info('waiting random_reauth_delay %ss', delay)
          time.sleep(delay)
          sys.exit(salt.defaults.exitcodes.SALT_KEEPALIVE)
      finally:
          lock.acquire(blocking=True)