Python - 在 Windows 中获取进程名称、CPU、内存使用情况和峰值内存使用情况 [英] Python - get process names,CPU,Mem Usage and Peak Mem Usage in windows

查看:96
本文介绍了Python - 在 Windows 中获取进程名称、CPU、内存使用情况和峰值内存使用情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得所有进程名称、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_percentpsutil.cpu_times.有关内存使用情况的信息,请使用 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、内存使用情况和峰值内存使用情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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