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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With