TODO: Make PID syntax checks more robust
439592
private boolean isPid(String value) {
        if ( (value == null)
                || (value.indexOf("+") != -1)
                || (value.indexOf("/") != -1)
                || (value.indexOf(" ") != -1) ) {
            return false;
        }
        int i = value.indexOf(":");
        return i > 0 && i < (value.length() - 1) && value.lastIndexOf(":") == i;
    }
816960
public final static float PID(String seq1, String seq2, int start, int end) {

		int s1len = seq1.length();
		int s2len = seq2.length();

		int len = Math.min(s1len, s2len);

		if (end < len) {
			len = end;
		}

		if (len < start) {
			start = len - 1; // we just use a single residue for the difference
		}

		int bad = 0;
		char chr1;
		char chr2;

		for (int i = start; i < len; i++) {

			chr1 = seq1.charAt(i);
			chr2 = seq2.charAt(i);

			if ('a' <= chr1 && chr1 <= 'z') {
				// TO UPPERCASE !!!
				// Faster than toUpperCase
				chr1 -= caseShift;
			}
			if ('a' <= chr2 && chr2 <= 'z') {
				// TO UPPERCASE !!!
				// Faster than toUpperCase
				chr2 -= caseShift;
			}

			if (chr1 != chr2 && !isGap(chr1) && !isGap(chr2)) {
				bad++;
			}
		}

		return ((float) 100 * (len - bad)) / len;
	}
5980
function delThread(pid) {
    //Delete worker entry from worker

    delete workers[pid];

    //Remove pid from pid array
    var position = pids.indexOf(pid);
    if (~position) pids.splice(position, 1);

    //Reset array index
    pids = pids.filter(function(){return true;});
}
61244
function ProcessWatcher(pid, parent) {
    var self = this;

    this.dead = false;

    // check first if process is alive
    if (exports.alive(pid) === false) {
      process.nextTick(function () {
        self.dead = true;
        self.emit('dead');
      });
      return self;
    }

    // use disconnect to detect parent death
    if (parent && exports.support.disconnect) {
      var listen = function() {
        self.dead = true;
        self.stop();
        self.emit('dead');
      }

      parent.once('disconnect', listen);
      this.stop = parent.removeListener.bind(null, 'disconnect', listen);

      this.on('newListener', function (eventName) {
        if (eventName !== 'cycle') return;

        process.nextTick(function () {
          self.emit('cycle');
        });
      });

      return self;
    }

    // fallback to an setInterval try/catch check
    var timer = setInterval(function () {
      if (exports.alive(pid) === false) {
        self.dead = true;
        self.stop();
        self.emit('dead');
      }
      self.emit('cycle');
    });
    this.stop = clearInterval.bind(null, timer);
  }
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),
    }
34929
def validate_unit_process_ids(self, expected, actual):
        """"""
        self.log.debug('Checking units for running processes...')
        self.log.debug('Expected PIDs: {}'.format(expected))
        self.log.debug('Actual PIDs: {}'.format(actual))

        if len(actual) != len(expected):
            return ('Unit count mismatch.  expected, actual: {}, '
                    '{} '.format(len(expected), len(actual)))

        for (e_sentry, e_proc_names) in six.iteritems(expected):
            e_sentry_name = e_sentry.info['unit_name']
            if e_sentry in actual.keys():
                a_proc_names = actual[e_sentry]
            else:
                return ('Expected sentry ({}) not found in actual dict data.'
                        '{}'.format(e_sentry_name, e_sentry))

            if len(e_proc_names.keys()) != len(a_proc_names.keys()):
                return ('Process name count mismatch.  expected, actual: {}, '
                        '{}'.format(len(expected), len(actual)))

            for (e_proc_name, e_pids), (a_proc_name, a_pids) in \
                    zip(e_proc_names.items(), a_proc_names.items()):
                if e_proc_name != a_proc_name:
                    return ('Process name mismatch.  expected, actual: {}, '
                            '{}'.format(e_proc_name, a_proc_name))

                a_pids_length = len(a_pids)
                fail_msg = ('PID count mismatch. {} ({}) expected, actual: '
                            '{}, {} ({})'.format(e_sentry_name, e_proc_name,
                                                 e_pids, a_pids_length,
                                                 a_pids))

                # If expected is a list, ensure at least one PID quantity match
                if isinstance(e_pids, list) and \
                        a_pids_length not in e_pids:
                    return fail_msg
                # If expected is not bool and not list,
                # ensure PID quantities match
                elif not isinstance(e_pids, bool) and \
                        not isinstance(e_pids, list) and \
                        a_pids_length != e_pids:
                    return fail_msg
                # If expected is bool True, ensure 1 or more PIDs exist
                elif isinstance(e_pids, bool) and \
                        e_pids is True and a_pids_length < 1:
                    return fail_msg
                # If expected is bool False, ensure 0 PIDs exist
                elif isinstance(e_pids, bool) and \
                        e_pids is False and a_pids_length != 0:
                    return fail_msg
                else:
                    self.log.debug('PID check OK: {} {} {}: '
                                   '{}'.format(e_sentry_name, e_proc_name,
                                               e_pids, a_pids))
        return None
271038
def isPIDValid(self, pid):
        
        ## Slightly copied wholesale from http://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid
        ## Thanks to http://stackoverflow.com/users/1777162/ntrrgc and http://stackoverflow.com/users/234270/speedplane
        class ExitCodeProcess(ctypes.Structure):
            _fields_ = [('hProcess', ctypes.c_void_p),
                        ('lpExitCode', ctypes.POINTER(ctypes.c_ulong))]
        SYNCHRONIZE = 0x100000
        PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
        process = self._kernel32.OpenProcess(SYNCHRONIZE|PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
        if not process:
            return False
        ec = ExitCodeProcess()
        out = self._kernel32.GetExitCodeProcess(process, ctypes.byref(ec))
        if not out:
            err = self._kernel32.GetLastError()
            if self._kernel32.GetLastError() == 5:
                # Access is denied.
                logging.warning("Access is denied to get pid info.")
            self._kernel32.CloseHandle(process)
            return False
        elif bool(ec.lpExitCode):
            # There is an exit code, it quit
            self._kernel32.CloseHandle(process)
            return False
        # No exit code, it's running.
        self._kernel32.CloseHandle(process)
        return True
848861
private int processId(final java.lang.Process process) {
    int processId = 0;
    try {
      final Field f = process.getClass().getDeclaredField("pid");
      f.setAccessible(true);

      processId = f.getInt(process);
    } catch (final Throwable e) {
      e.printStackTrace();
    }

    return processId;
  }
286729
def _pid_to_id(self, pid):
        """"""
        return d1_common.url.joinPathElements(
            self._base_url,
            self._version_tag,
            "resolve",
            d1_common.url.encodePathElement(pid),
        )
1249512
public static String normalize(String pidString)
            throws MalformedPIDException {
        if (pidString == null) {
            throw new MalformedPIDException("PID is null.");
        }
        
        return normalize(pidString, 0, pidString.length());
    }
910956
def init_pid(self, kp, ki, kd):
        """"""
        p, i, d = map(lambda x: int(x * (2 ** 16)), (kp, ki, kd))
        self._set_as_int(Addr.PConstant, p, 4)
        self._set_as_int(Addr.IConstant, i, 4)
        self._set_as_int(Addr.DConstant, d, 4)
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)
    )
473940
def get_stdin_pid(cached_result=None):
    """"""
    if cached_result is None:
        try:
            tasks = os.listdir('/proc/self/task')
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise
            cached_result = os.getpid()
        else:
            tasks.remove(str(os.getpid()))
            assert len(tasks) == 1
            cached_result = int(tasks[0])
    return cached_result
745004
function pidOf( procName, callback ){
    if ( isString( procName )){
        var pids = [];

        procStat( procName, function( err, processes ){
            processes.object.forEach( function( proc ){
                pids.push( proc.pid )
            });

            callback( err, pids )
        })
    } else callback( new Error( 'A non-string process name was supplied' ), null, null )
}
1099856
function(eventName, cpuNumber, pid, ts, eventBase) {
      var event = /crtc=(\d+), seq=(\d+)/.exec(eventBase.details);
      if (!event)
        return false;

      var crtc = parseInt(event[1]);
      var seq = parseInt(event[2]);
      this.drmVblankSlice(ts, 'vblank:' + crtc,
          {
            crtc: crtc,
            seq: seq
          });
      return true;
    }
307297
public static PID getPID(String pidString) throws MalformedPidException {
        try {
            return new PID(pidString);
        } catch (MalformedPIDException e) {
            throw new MalformedPidException(e.getMessage());
        }
    }
1103676
private long getPID() {
        String commandOutput = executeCommand("$pid").getCommandOutput();

        //Remove all non numeric characters
        commandOutput = commandOutput.replaceAll("\\D", "");

        if (!commandOutput.isEmpty()) {
            return Long.valueOf(commandOutput);
        }

        return -1;
    }