def find_pids_status(regex): ret = [] for d in os.listdir('/proc'): try: path = '/proc/%s/status' % d if os.path.isfile(path): fp = open(path) status = fp.readline() fp.close() if regex.search(status.split()[1]): ret.append(int(d)) except: pass return ret
def find_pids_cmdline(regex): ret = [] for d in os.listdir('/proc'): try: path = '/proc/%s/cmdline' % d if os.path.isfile(path): fp = open(path) cmdline = fp.read() fp.close() if regex.search(cmdline): ret.append(int(d)) except: pass return ret