Psutil.process_iter () does not return all running processes

I am using psutil 2.1.2 on python 64 bit on Windows 8.1. I am using psutil.process_iter () to iterate over running processes to get detailed information about a specific process. for some reason I am not getting this process even though it shows up in Task Manager and Process Explorer

for proc in psutil.process_iter():
    try:
        if proc.name() == 'svchost.exe':  # patch for debugging 
            pass  #script never gets here
        opened_files = proc.open_files()
        opened_files = [opened_file[0] for opened_file in opened_files]
        if file_path in opened_files:
            processes.append(proc)
    except (psutil.AccessDenied, psutil.NoSuchProcess):
        pass

      

I have checked the proc name and this is never the process I am looking for. an example of a process i can't see is svchost.exe

Thanks for the help!

+3


source to share


2 answers


For some (actually many) processes, proc.open_files () will throw an AccessDenied exception, which is probably why you don't see "all" processes. Task Manager and Process Explorer show more information than psutil because they have less privilege restrictions (see: They can "fetch" more information from processes without encountering "access denied" errors). Using psutil, you can see all processes (PIDs), but you cannot "query" all of them.



+2


source


This bug https://github.com/giampaolo/psutil/issues/599 is probably the cause of this issue. Fixed.



+1


source







All Articles