Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

psutil.process_iter() doesn't return all running processes

Tags:

python

psutil

I'm using psutil 2.1.2 on python 64 bit on windows 8.1. I'm using psutil.process_iter() to iterate over the running processes to get details on a specific process. for some reason I don't get the process even though it is displayed in the Task Manager and the 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 checked the proc name and it is never the process I'm looking for. example of a process I don't see is svchost.exe

Thanks for the help!

like image 318
Ido A Avatar asked Oct 29 '14 09:10

Ido A


1 Answers

For some (actually many) processes proc.open_files() will result in an AccessDenied exception so probably that is why you don't "see" all processes. Task manager and Process Explorer show more information than psutil because they have less privilege limitations (see: they can "extract" more info from the processes without bumping into 'access denied' errors). By using psutil you're able to see all processes (PIDs) though, only you won't be able to "query" all of them.

like image 180
Giampaolo Rodolà Avatar answered Nov 02 '22 22:11

Giampaolo Rodolà