识别给定应用程序池的 w3wp System.Diagnostics.Process

发布于 2024-08-19 17:58:03 字数 542 浏览 13 评论 0原文

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

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

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

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

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

如何识别我的第二个 w3wp 进程,知道它的应用程序池?

我找到了相应的线程,但没有合适的答案: 查看进程的可靠方法- IIS6 应用程序池的具体性能统计信息

谢谢

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).

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);

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

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

慢慢从新开始 2024-08-26 17:58:03

您可以使用 WMI 来识别哪个应用程序池给定的 w3wp.exe 进程所属:

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);
    }
}

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);
    }
}
ま昔日黯然 2024-08-26 17:58:03

您还可以使用 IIS ServerManager 组件获取 PID;方式,如果您需要在代码中访问它,而不需要重定向和解析控制台输出;

public static int GetIISProcessID(string appPoolName)
{
    Microsoft.Web.Administration.ServerManager serverManager = new   
        Microsoft.Web.Administration.ServerManager();
    foreach (WorkerProcess workerProcess in serverManager.WorkerProcesses)
    {
        if (workerProcess.AppPoolName.Equals(appPoolName))
            return workerProcess.ProcessId;
    }

    return 0;
}

You can also get the PID using the IIS ServerManager component; way, if you need to access it in code, without redirecting and parsing console output;

public static int GetIISProcessID(string appPoolName)
{
    Microsoft.Web.Administration.ServerManager serverManager = new   
        Microsoft.Web.Administration.ServerManager();
    foreach (WorkerProcess workerProcess in serverManager.WorkerProcesses)
    {
        if (workerProcess.AppPoolName.Equals(appPoolName))
            return workerProcess.ProcessId;
    }

    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文