Python-在Windows中获取进程名称,CPU,Mem用法和Peak Mem用法
我想获取所有进程名称,CPU,内存使用情况和峰值内存使用情况的列表.我希望我可以使用ctypes.但我很高兴听到其他选择.谢谢您的时间.
I am wanting to get a list of all the process names, CPU, Mem Usage and Peak Mem Usage. I was hoping I could use ctypes. but I am happy to hear any other options. Thanks for your time.
您可以使用 psutil
You can use psutil
.
例如,获取进程名称列表:
For example, to obtain the list of process names:
process_names = [proc.name() for proc in psutil.process_iter()]
有关CPU的信息,请使用 psutil.cpu_percent
或psutil.virtual_memory
.
For info about the CPU use psutil.cpu_percent
or psutil.cpu_times
.
For info about memory usage use psutil.virtual_memory
.
请注意,psutil可与Linux,OS X,Windows,Solaris和FreeBSD以及python 2.4至3.3一起使用.
Note that psutil works with Linux, OS X, Windows, Solaris and FreeBSD and with python 2.4 through 3.3.