def __select_process(self):
        sub_proc = None
        if self.__commandline_matcher is not None:
            try:
                # Spawn a process to run ps and match on the command line.  We only output two
                # fields from ps.. the pid and command.
                sub_proc = Popen(['ps', 'ax', '-o', 'pid,command'],
                                 shell=False, stdout=PIPE)

                sub_proc.stdout.readline()
                for line in sub_proc.stdout:
                    line = line.strip()
                    if line.find(' ') > 0:
                        pid = int(line[:line.find(' ')])
                        line = line[(line.find(' ') + 1):]
                        if re.search(self.__commandline_matcher, line) is not None:
                            return pid
                return None
            finally:
                # Be sure to wait on the spawn process.
                if sub_proc is not None:
                    sub_proc.wait()
        else:
            # See if the specified target pid is running.  If so, then return it.
            try:
                # Special case '$$' to mean this process.
                if self.__target_pid == '$$':
                    pid = os.getpid()
                else:
                    pid = int(self.__target_pid)
                os.kill(pid, 0)
                return pid
            except OSError:
                # If we get this, it means we tried to signal a process we do not have permission to signal.
                # If this is the case, we won't have permission to read its stats files either, so we ignore it.
                return None
Helper for pulling a keyed value off various types of objects
dataset/ETHPy150Open scalyr/scalyr-agent-2/scalyr_agent/builtin_monitors/linux_process_metrics.py/ProcessMonitor.__select_process--crossover with--dataset/ETHPy150Open flask-restful/flask-restful/flask_restful/fields.py/get_value