Reads pidfile and returns False if its PID is ours, else a printable (maybe falsey) value.
763863
def _check_pid_changed(self):
    """"""
    try:
      with open(os.path.join(self._build_root, self._pantsd_pidfile), "r") as f:
        pid_from_file = f.read()
    except IOError:
      return "[no file could be read]"
    if int(pid_from_file) != os.getpid():
      return pid_from_file
    else:
      return False
472309
def pid(self):
        
        try:

            with open(self.pidfile, 'r') as pidfile:

                try:

                    pid = int(pidfile.read().strip())

                except ValueError:

                    return None

                try:

                    os.kill(pid, 0)

                except OSError as e:

                    if e.errno == errno.EPERM:

                        return pid

                    elif e.errno == errno.ESRCH:

                        return None

                    LOG.exception(
                        "os.kill returned unhandled error "
                        "{0}".format(e.strerror)
                    )
                    sys.exit(exit.PIDFILE_ERROR)

                return pid

        except IOError:

            if not os.path.isfile(self.pidfile):

                return None

            LOG.exception("Failed to read pidfile {0}.".format(self.pidfile))
            sys.exit(exit.PIDFILE_INACCESSIBLE)
1015191
def _check_read(self, fd, nbytes):  # type: (...) -> bytes
        
        result = fd.read(nbytes)

        if (not result and nbytes > 0) or len(result) != nbytes:
            raise InvalidZoneinfoFile(
                "Expected {} bytes reading {}, "
                "but got {}".format(nbytes, fd.name, len(result) if result else 0)
            )

        if PY2:
            return bytearray(result)

        return result
140673
def read(self):
        
        if not self.fname:
            return
        try:
            with open(self.fname, "r") as f:
                wpid = int(f.read() or 0)
                if wpid <= 0:
                    return
                return wpid
        except IOError:
            return
765073
function(str,pid){
		var matches = str.match(/!?[a-z0-9]+/g), isdisp = true;
		if(!!matches){
			isdisp = false;
			for(var i=0;i<matches.length;i++){
				if(matches[i].charAt(0)!=="!"){ if(matches[i]===pid){ isdisp = true;}}
				else                          { isdisp = (matches[i].substr(1)!==pid);}
			}
		}
		return isdisp;
	}
196821
def kill(pid_file):
    
    try:
        with open(pid_file) as f:
            os.kill(int(f.read()), 9)
        os.remove(pid_file)
    except (IOError, OSError):
        return False
    return True
1023028
def is_valid_pid_to_be_updated(did):
    """"""
    return (
        is_existing_object(did)
        and not is_local_replica(did)
        and not is_archived(did)
        and not is_obsoleted(did)
    )
1001748
public void read() {
    String pid = "-1";
    try {
      pid = getProcessId();
      _pid = pid;
    }
    catch (Exception ignore) {}

    File f = new File ("/proc/stat");
    if (! f.exists()) {
      return;
    }

    try {
      readSystemProcFile();
      readProcessProcFile(pid);
      readProcessNumOpenFds(pid);
      readProcessStatusFile(pid);
      parseSystemProcFile(_systemData);
      parseProcessProcFile(_processData);
      parseProcessStatusFile(_processStatus);
    }
    catch (Exception ignore) {}
  }
290240
def __get_pid_by_scanning(self):
        ''
        dwProcessId = None
        dwThreadId = self.get_tid()
        with win32.CreateToolhelp32Snapshot(win32.TH32CS_SNAPTHREAD) as hSnapshot:
            te = win32.Thread32First(hSnapshot)
            while te is not None:
                if te.th32ThreadID == dwThreadId:
                    dwProcessId = te.th32OwnerProcessID
                    break
                te = win32.Thread32Next(hSnapshot)
        if dwProcessId is None:
            msg = "Cannot find thread ID %d in any process" % dwThreadId
            raise RuntimeError(msg)
        return dwProcessId
134114
def pid_from_file
      if File.exist?(pid_file_path)
        pid = File.read(pid_file_path)
        pid.length > 0 ? pid.strip.to_i : nil
      else
        nil
      end
    end
1025466
def read_pid_from_pidfile(pidfile_path):
    
    pid = None
    try:
        pidfile = open(pidfile_path, 'r')
    except IOError:
        pass
    else:
        # According to the FHS 2.3 section on PID files in /var/run:
        # 
        #   The file must consist of the process identifier in
        #   ASCII-encoded decimal, followed by a newline character.
        # 
        #   Programs that read PID files should be somewhat flexible
        #   in what they accept; i.e., they should ignore extra
        #   whitespace, leading zeroes, absence of the trailing
        #   newline, or additional lines in the PID file.

        line = pidfile.readline().strip()
        try:
            pid = int(line)
        except ValueError:
            pass
        pidfile.close()

    return pid
565424
def is_running(pid):
    
    process = get_process(pid)
    if process and process.is_running() and process.status() != "zombie":
        return True
    else:
        return False
1031315
function pidFind(pid) {
  if (!_.isFinite(pid)) return false;
  try {
    if (runningAsRoot()) {
      return process.kill(pid, 0);
    } else {
      return !!ps(pid);
    }
  } catch (e) {
    return false;
  }
}
272056
def pid(self):
        
        pf = self.path('cmd.pid')
        if not os.path.exists(pf):
            return None
        with open(pf, 'r') as f:
            return int(f.read())
1281700
def read_pid_stat(pid):
    
    return {
        "utime": random.randint(0, 999999999),
        "stime": random.randint(0, 999999999),
        "cutime": random.randint(0, 999999999),
        "cstime": random.randint(0, 999999999),
    }
912917
def _pid_is_alive(cls, pid, timeout):
        """"""
        try:
            proc = psutil.Process(pid)
        except psutil.NoSuchProcess:
            return False

        try:
            proc.wait(timeout=timeout)
        except psutil.TimeoutExpired:
            return True

        return False
348833
def _get_pidfile_path(self):
        
        if self.config.daemon.pidfile:
            pidfile = path.abspath(self.config.daemon.pidfile)
            if not os.access(path.dirname(pidfile), os.W_OK):
                raise ValueError('Cannot write to specified pid file path'
                                 ' %s' % pidfile)
            return pidfile
        app = sys.argv[0].split('/')[-1]
        for pidfile in ['%s/pids/%s.pid' % (os.getcwd(), app),
                        '/var/run/%s.pid' % app,
                        '/var/run/%s/%s.pid' % (app, app),
                        '/var/tmp/%s.pid' % app,
                        '/tmp/%s.pid' % app,
                        '%s.pid' % app]:
            if os.access(path.dirname(pidfile), os.W_OK):
                return pidfile
        raise OSError('Could not find an appropriate place for a pid file')