os:windows professional
我正在尝试使用psutil获取进程列表及其cpu使用情况,我以管理员身份运行脚本,遇到进程DymoPnpService.exe时失败,可能是什么问题?
import psutil
def process():
plist = psutil.get_process_list()
plist = sorted(plist, key=lambda i: i.name)
for i in plist:
print i.name, i.get_cpu_percent()
def main():
process()
main()
AcroRd32.exe 0.0 AcroRd32.exe 0.0 DymoPnpService.exe
Traceback (most recent call last):
File "C:\Users\krisdigitx\Documents\windowsutil.py", line 13, in <module>
main()
File "C:\Users\krisdigitx\Documents\windowsutil.py", line 10, in main
process()
File "C:\Users\krisdigitx\Documents\windowsutil.py", line 7, in process
print i.name, i.get_cpu_percent()
File "C:\Python27\lib\site-packages\psutil\__init__.py", line 330, in get_cpu_percent
pt1 = self._platform_impl.get_cpu_times()
File "C:\Python27\lib\site-packages\psutil\_psmswindows.py", line 125, in wrapper
raise AccessDenied(self.pid, self._process_name)
AccessDenied: (pid=1832, name='DymoPnpService.exe')
更多研究:
奇怪我可以从windows命令提示符运行程序......但它在python ide
中失败答案 0 :(得分:5)
在cmd.exe提示符下运行:tasklist /FI "IMAGENAME eq DymoPnpService.exe" /V
并检查“用户名”。如果它是“NT AUTHORITY \ SYSTEM”那么它可能故意不允许甚至管理员帐户获得proc的cpu时间,%等。
获取Process Explorer的副本并找到该过程的路径,然后选中“首选项”右键菜单选项的“安全”选项卡。要解决此问题可能能够编辑DymoPnpService.exe可执行文件的所有者或权限,但这可能会导致Windows中出现意外问题。
如果流程不允许您获取有关它的详细信息,您也可以继续循环:
import psutil
def process():
plist = psutil.get_process_list()
plist = sorted(plist, key=lambda i: i.name)
for i in plist:
try:
print i.name, i.get_cpu_percent()
except AccessDenied:
print "'%s' Process is not allowing us to view the CPU Usage!" % i.name
def main():
process()
main()
答案 1 :(得分:0)
从版本0.6.0开始,Windows上的psutil将不再为不同的进程方法(其中包含cpu_percent())引发AccessDenied: https://groups.google.com/forum/?fromgroups#!topic/psutil/oxAd0BuAzt0%5B1-25%5D