http://CC318.com

一个程序的窝

我的窝窝 http://CC318.com 这里有更多内容,不信你试试.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

获得各进程占用的CPU

Posted on 2009-02-13 11:08  chaoliu  阅读(149)  评论(0)    收藏  举报
投机取巧的做法如下:

C# code

Process p
= new Process();

p.StartInfo.FileName
= "cmd.exe";

p.StartInfo.UseShellExecute
= false;

p.StartInfo.RedirectStandardInput
= true;

p.StartInfo.RedirectStandardOutput
= true;

p.StartInfo.RedirectStandardError
= true;

p.StartInfo.CreateNoWindow
= true;

p.Start();

p.StandardInput.WriteLine(
"tasklist /V");

p.StandardInput.WriteLine(
"exit");

string strRst = p.StandardOutput.ReadToEnd();
string tag="========================================================================";
string w = strRst.Substring(strRst.IndexOf(tag) + tag.Length);

string[] res = w.Split('"n');
http://CC318.com