def checkProcess(processName): if platform.system().lower == "windows": WMI = GetObject('winmgmts:') pList = [] processes = WMI.instancesOf('Win32_Process') for process in processes: if processName == process.Properties_('Name').Value: return True return False else: pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] for pid in pids: try: cmdLine = open(os.path.join('/proc', pid, 'cmdline'), 'rb').read().split(bytes('\0', 'utf-8')) if len(cmdLine) > 1: process = cmdLine[0].split(bytes(' ', 'utf-8'))[0].split( bytes('/', 'utf-8'))[-1] if process == bytes(processName, 'utf-8'): FLAG = True return True else: continue except IOError: # proc has already terminated continue return False
def getProcessesList(): PROCESSES_LIST_ = [] getObj_ = GetObject('winmgmts:') processes_ = getObj_.instancesOf('Win32_Process') for ps_ in processes_: PROCESSES_LIST_.append(ps_.Properties_('Name').Value) return PROCESSES_LIST_