C# 列出所有进程及其当前内存和 CPU 消耗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1248129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
List all processes and their current memory & CPU consumption?
提问by Alex
How can I get a list of all processes in C# and then for each process current memory and CPU consumption?
如何获取 C# 中所有进程的列表,然后获取每个进程的当前内存和 CPU 消耗?
Sample code is highly appreciated.
示例代码受到高度赞赏。
采纳答案by Brian Rasmussen
The Process classhas a GetProcesses method that will let you enumerate the running processes and list a bunch of stats like memory usage and CPU time. Look at the documentation under properties for the stats.
该工艺类具有GetProcesses方法,可以让你枚举正在运行的进程,并列出了一堆像内存使用和CPU时间统计的。查看属性下的文档以获取统计信息。
Memory usage is a complex matter. There is really no single number, that describe the usage. Please see Russinovich's excellent series on the matter. The first installment is here: http://blogs.technet.com/markrussinovich/archive/2008/07/21/3092070.aspx
内存使用是一个复杂的问题。真的没有一个数字来描述用法。请参阅 Russinovich 关于此事的精彩系列。第一期在这里:http: //blogs.technet.com/markrussinovich/archive/2008/07/21/3092070.aspx