得到一个进程专用工作集内存 [英] Get a processes Private Working Set memory

查看:2023
本文介绍了得到一个进程专用工作集内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图以编程方式获得一个进程的专用工作集。

Trying to programmatically get the private working set of a process.

目前,我能得到工作设置没有问题,但遇到了麻烦私人工作集。

Currently I am able to get the working set without issue but having trouble getting the private working set.

下面的方法:

private void GetProcessesForServer(string serverName)
{
    var runningProcesses = new Process[0];

    try
    {
        runningProcesses = Process.GetProcesses(serverName);

    }
    catch (Exception e)
    {
        ResultsPanel.Controls.Add(new Label { Text = string.Format("There was an error: {0}", e.GetBaseException().Message) });
    }

    IOrderedEnumerable<CustomProcess> processes = runningProcesses
        .Select(process => new CustomProcess(process.Id, process.ProcessName, (process.WorkingSet64 / 1024)))
        .ToList()
        .OrderBy(process => process.ProcessName);

    if (processes.Count() > 0)
        ResultsLabel.Text = string.Format("Current running processes on {0}", ServerNamesDropDown.SelectedItem.Text);

    ResultsGridView.DataSource = processes;
    ResultsGridView.DataBind();
}

所以我传递一个服务器的名称,然后试图让所有正在运行的进程的服务器,然后进程列表绑定到网格视图。一切正常,没有任何问题,但是我需要得到私人工作集 - 类似于您在Windows任务管理器中看到 - 而不是总的工作集

So I'm passing in a server name then trying to get all the running processes for that server then binding the list of processes to a grid view. Everything works without any issues however I need to get the private working set - similar to what you see in Windows Task manager - rather than the total working set.

非常感谢, 蒂姆·

推荐答案

在Windows Vista和超越存在的工作集 - 私人中的过程类别的性能计数器(见的 MSDN )。

On Windows Vista and beyond there is the "Working Set - Private" performance counter in the "Process" category (see msdn).

由于你是这样的,你可以使用 System.Diagonstics.PerformanceCounter 类查询这个信息的平台。

Given you are on such a platform you could use the System.Diagonstics.PerformanceCounter class to query this information.

要建立一个进程ID和一个给定的性能计数器实例之间的联系,使用标识进程的一类计数器。换句话说:查找实例里的ID进程柜台是你想要的进程ID,在读的价值工作集 - 专用柜台

To establish a link between a process ID and a given performance counter instance, use the "ID Process" counter of a category. In other words: lookup the instance where the "ID Process" counter is your desired process ID, the read the value of the "Working Set - Private" counter.

提示:如果您需要查询所有值的所有进程使用 System.Diagonstics.PerformanceCounterCategory.ReadCategory()调用而不是,因为它是非常快的读取个人计数器所有过程/实例。

Hint: if you need to query all values for all processes use the System.Diagonstics.PerformanceCounterCategory.ReadCategory() call instead, as it is much faster the reading individual counters for all processes/instances.

更新:有在 $文章C $的CProject ,显示如何计算在XP / 2000的值,如果你一定要。我没有测试过,所以不要怪我; - )

Update: There is an article on codeproject that shows how to calculate that value on XP/2000, if you must. I have not tested it, so don't blame me ;-)

更新2 :您可能还需要签这个<一href="http://stackoverflow.com/questions/2611141/calculate-private-working-set-memory-using-c">stackoverflow提问/回答。

Update 2: You may also want to checkout this stackoverflow question/answer.

这篇关于得到一个进程专用工作集内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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