code: def check_process(pidfile):
      
      # Check pid file
      try:
          handle = open(pidfile, 'r')
      except IOError as exc:
          if exc.errno == errno.ENOENT:
              # pid file disappeared
              return False, 0
          raise
  
      try:
          pid = int(handle.read().strip(), 10)
      except (TypeError, ValueError) as exc:
          raise EnvironmentError("Invalid PID file '%s' (%s), won't start!" % (pidfile, exc))
      finally:
          handle.close()
  
      # Check process
      try:
          os.kill(pid, 0)
      except EnvironmentError as exc:
          return False, pid
      else:
          return True, pid
docs: Read pid file and check process status.
          Return (running, pid).