我在windows 8.1上的python 64位上使用psutil 2.1.2。我使用psutil.process_iter()遍歷正在運行的進程以獲取特定進程的詳細信息。由於某種原因,我不明白,即使它顯示在任務管理器的進程和Process Explorer的psutil.process_iter()不會返回所有正在運行的進程
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
我檢查了PROC名稱,這是從來沒有我在尋找的過程。 我看不到的過程的一個例子是svchost.exe
感謝您的幫助!
從另一個方向看,使用從psutil.pids()獲得的進程PID。 'psutil.Process(pid).open_files()'產生'psutil.AccessDenied'。在proc對象中,這個PID的BTW進程名稱爲None。有沒有辦法解決這個問題? – 2014-10-29 14:49:48