Python-在Windows中获取进程名称,CPU,Mem用法和Peak Mem用法 [英] Python - get process names,CPU,Mem Usage and Peak Mem Usage in windows

查看:350
本文介绍了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.

这篇关于Python-在Windows中获取进程名称,CPU,Mem用法和Peak Mem用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆