Find if process is running in Windows psutil

KAKAK picture KAKAK · Jun 10, 2014 · Viewed 12k times · Source
process_name = "CCC.exe"
for proc in psutil.process_iter():
    if proc.name == process_name:
        print ("have")
    else: 
        print ("Dont have")

I know for the fact that CCC.exe is running. I tried this code with both 2.7 and 3.4 python I have imported psutil as well. However the process is there but it is printing "Dont have".

Answer

vuolter picture vuolter · May 13, 2016

name is a method of proc:

process_name = "CCC.exe"
for proc in psutil.process_iter():
    if proc.name() == process_name:
        print ("have")
    else: 
        print ("Dont have")