确定给定应用程序池的w3wp System.Diagnostics.Process [英] Identify the w3wp System.Diagnostics.Process for a given application pool

查看:255
本文介绍了确定给定应用程序池的w3wp System.Diagnostics.Process的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上运行的网站很少。

I got few web sites running on my server.

我在应用程序中有一个诊断页面,显示内存量对于当前进程(非常有用)。

I have a "diagnostic" page in an application that shows the amount of memory for the current process (very useful).

现在这个应用程序与另一个应用程序链接,我希望我的诊断页面能够显示大量的另一个w3wp进程的内存。

Now this app is 'linked' to another app, and I want my diagnostic page to be able to display the amot of memory for another w3wp process.

为了获得内存量,我使用了一个简单的代码:

To get the amount of memory, I use a simple code :

var process = Process.GetProcessesByName("w3wp");
string memory = this.ToMemoryString(process.WorkingSet64);

如何了解我的第二个w3wp进程,了解其应用程序池?

How can I identify my second w3wp process, knowing its application pool ?

我找到了相应的帖子,但没有合适的答案:
可靠的方式来查看IIS6应用程序池上特定于流程的性能统计信息

I found a corresponding thread, but no appropriate answer : Reliable way to see process-specific perf statistics on an IIS6 app pool

谢谢

推荐答案

你可以使用 WMI ,用于标识给定 w3wp.exe 进程所属的应用程序池:

You could use WMI to identify to which application pool a given w3wp.exe process belongs:

var scope = new ManagementScope(@"\\YOURSERVER\root\cimv2");
var query = new SelectQuery("SELECT * FROM Win32_Process where Name = 'w3wp.exe'");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
    foreach (ManagementObject process in searcher.Get())
    {
        var commandLine = process["CommandLine"].ToString();
        var pid = process["ProcessId"].ToString();
        // This will print the command line which will look something like that:
        // c:\windows\system32\inetsrv\w3wp.exe -a \\.\pipe\iisipm49f1522c-f73a-4375-9236-0d63fb4ecfce -t 20 -ap "NAME_OF_THE_APP_POOL"
        Console.WriteLine("{0} - {1}", pid, commandLine);
    }
}

这篇关于确定给定应用程序池的w3wp System.Diagnostics.Process的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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