code: def pid_exists(pid):
      
  
      if os.name == 'nt':
          # check the output of TASKLIST command
          returncode, stdout, stderr = capture_command(['TASKLIST', '/FO', 'CSV', '/NH', '/FI', 'PID eq %d' % pid])
          return stdout[:1] == b'"'
      else:
          if pid == 0:
              # According to "man 2 kill" PID 0 has a special meaning:
              # it refers to <<every process in the process group of the
              # calling process>> so we don't want to go any further.
              # If we get here it means this UNIX platform *does* have
              # a process with id 0.
              return True
          try:
              os.kill(pid, 0)
          except OSError as err:
              if err.errno == errno.ESRCH:
                  # ESRCH == No such process
                  return False
              elif err.errno == errno.EPERM:
                  # EPERM clearly means there's a process to deny access to
                  return True
              else:
                  # According to "man 2 kill" possible error values are
                  # (EINVAL, EPERM, ESRCH) therefore we should never get
                  # here. If we do let's be explicit in considering this
                  # an error.
                  raise err
          else:
              return True
docs: Check whether pid exists in the current process table.
  
      stole from https://github.com/giampaolo/psutil/blob/master/psutil/_psposix.py