def find_pids(self, name, search_string, exact_match, ignore_ad=True,
                  refresh_ad_cache=True):
        """
        Create a set of pids of selected processes.
        Search for search_string
        """
        if not self.should_refresh_pid_cache(name):
            return self.pid_cache[name]

        ad_error_logger = self.log.debug
        if not ignore_ad:
            ad_error_logger = self.log.error

        refresh_ad_cache = self.should_refresh_ad_cache()

        matching_pids = set()

        for proc in psutil.process_iter():
            # Skip access denied processes
            if not refresh_ad_cache and proc.pid in self.ad_cache:
                continue

            found = False
            for string in search_string:
                try:
                    # FIXME 6.x: All has been deprecated from the doc, should be removed
                    if string == 'All':
                        found = True
                    if exact_match:
                        if proc.name() == string:
                            found = True
                    else:
                        cmdline = proc.cmdline()
                        if string in ' '.join(cmdline):
                            found = True
                except psutil.NoSuchProcess:
                    self.log.warning('Process disappeared while scanning')
                except psutil.AccessDenied, e:
                    ad_error_logger('Access denied to process with PID %s', proc.pid)
                    ad_error_logger('Error: %s', e)
                    if refresh_ad_cache:
                        self.ad_cache.add(proc.pid)
                    if not ignore_ad:
                        raise
                else:
                    if refresh_ad_cache:
                        self.ad_cache.discard(proc.pid)
                    if found:
                        matching_pids.add(proc.pid)
                        break

        self.pid_cache[name] = matching_pids
        self.last_pid_cache_ts[name] = time.time()
        return matching_pids
dataset/ETHPy150Open serverdensity/sd-agent/checks.d/process.py/ProcessCheck.find_pids/original