简体   繁体   English

IIS应用程序池PID

[英]IIS Application pool PID

is anyone familiar with a way to get the Application pool that is associated with a process ID ?有没有人熟悉获取与进程 ID 关联的应用程序池的方法? I am using Win32_Process to query the W3WP services and return the PID now I am trying to get the app pool associated with it.我正在使用 Win32_Process 查询 W3WP 服务并返回 PID 现在我正在尝试获取与其关联的应用程序池。

On Windows Server 2008 this has changed.在 Windows Server 2008 上,这已经改变了。

in systemroot\\system32\\inetsrv you find the appcmd.exe在 systemroot\\system32\\inetsrv 中,您可以找到 appcmd.exe

using使用

appcmd list wp appcmd 列表 wp

you get a list of all the worker processes and which apppool they are serving.您将获得所有工作进程的列表以及它们正在服务的应用程序池。

You might need to run this in a shell with Administrator privileges.您可能需要在具有管理员权限的 shell 中运行它。

If you are just using command line to figure it out ad-hoc you can do this too:如果您只是使用命令行来临时解决,您也可以这样做:

The script is already placed in systemroot\\system32 on Windows Server 2003 so simply go to your Command Prompt and type in iisapp.vbs (the .vbs is optional) and you'll have an instant list of all the App Pool information you've always wanted to know.该脚本已放置在 Windows Server 2003 上的 systemroot\\system32 中,因此只需转到您的命令提示符并键入 iisapp.vbs(.vbs 是可选的),您将获得所有应用程序池信息的即时列表一直想知道。 You may need to type cscript iisapp.vbs if CScript isn't your default WSH script host.如果 CScript 不是您的默认 WSH 脚本宿主,您可能需要键入 cscript iisapp.vbs。

Let's see an example of the output:让我们看一个输出示例:

W3WP.exe PID: 1468 AppPoolId: AppPoolForSite1.com
W3WP.exe PID: 3056 AppPoolId: AppPoolForSite2.com
W3WP.exe PID: 1316 AppPoolId: AppPoolForSite3.com

Direct from the horse's mouth, Microsoft documents this .直接从马的嘴里,微软记​​录了这一点

I just discovered that you can also find this in the UI for IIS 7. Select your web server node and open "Worker Processes".我刚刚发现您也可以在 IIS 7 的 UI 中找到它。选择您的 Web 服务器节点并打开“工作进程”。 This will show the name of each Application Pool along with its Process ID and utilization details.这将显示每个应用程序池的名称及其进程 ID 和利用率详细信息。

If you're running on Windows Server 2008 and you ONLY want the PID, to feed to another script or command, you can use this:如果您在 Windows Server 2008 上运行并且您只想要 PID 提供给另一个脚本或命令,您可以使用这个:

c:\windows\system32\inetsrv\appcmd list wps /apppool.name:"My Application Pool" /text:WP.NAME

For example, to create a batch script that creates a memory dump of a particular app pool, use this:例如,要创建一个批处理脚本来创建特定应用程序池的内存转储,请使用以下命令:

c:\windows\system32\inetsrv\appcmd list wps /apppool.name:"My Application Pool" /text:WP.NAME > "%temp%\pid.txt"
for /F %%a in (%temp%\pid.txt) do c:\debugger\adplus.exe -hang -o d:\dumps -p %%a
pause

You can use task manager to view the user name under which the process runs (which in general is the same as the application pool name) and the process ID, but you have to turn on these columns in task manager, and it also assumes the user name that the process runs under is the same as the application pool name (which is the default as far as I know, unless one is using Sharepoint and the like).可以使用任务管理器查看进程运行的用户名(一般与应用程序池名称相同)和进程ID,但必须在任务管理器中打开这些列,并且还假定进程在其下运行的用户名与应用程序池名称相同(据我所知,这是默认值,除非使用 Sharepoint 等)。
Also note that all methods listed in this page might only display the processes that are currently running, which means that if your particular process has shut down due to idle time you have first to use the site in order to bring the process up in the list, and in your case it means you should first access all sites to make sure that the process associated with them is runing.另请注意,此页面中列出的所有方法可能仅显示当前正在运行的进程,这意味着如果您的特定进程因空闲时间而关闭,您必须首先使用该站点才能将该进程显示在列表中,就您而言,这意味着您应该首先访问所有站点以确保与它们关联的进程正在运行。

ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

Try working with this and it should get you what you need.尝试使用它,它应该可以满足您的需求。

Open IIS Manager ( Run > Inetmgr ), Select root level from left site navigation tree and from “Features View Panel” select “Worker Processes”打开 IIS 管理器(运行 > Inetmgr),从左侧站点导航树中选择根级别,然后从“功能视图面板”中选择“工作进程”

Click on the “Worker Processes” to get details of all worker process which are currently running单击“工作进程”以获取当前正在运行的所有工作进程的详细信息

From this list you will get application pool name, process id从此列表中,您将获得应用程序池名称、进程 ID

This should do it.这应该这样做。

public string getAppPoolName(int pid)
{            
    ServerManager serverManager = new ServerManager();

    ApplicationPoolCollection apc = serverManager.ApplicationPools;

    foreach (var app in apc)
    {
        var workers = app.WorkerProcesses;

        foreach (var w in workers)
        {                   
            if (w.ProcessId == pid)
            {
                return app.Name;
            }
        }
    }

    return string.Empty;
}

PID of and Application Pool giving its name: PID 和应用程序池给出了它的名字:

$AppPoolName = 'AppPoolForSite1'
(Get-ItemProperty IIS:\AppPools\$AppPoolName -Name WorkerProcesses).Collection.processId

If you have multiple app pools and want to the know PID of each.如果您有多个应用程序池并想知道每个应用程序池的 PID。 You can run the powershell below which will iterate through all the app pools on the machine, query the PID, and displays the App Pool Name and PID in a nice table format.您可以运行下面的 powershell,它将遍历机器上的所有应用程序池,查询 PID,并以漂亮的表格格式显示应用程序池名称和 PID。

import-module webadministration

$dirs = dir IIS:\AppPools\

foreach($dir in $dirs)
{
    Write-Output([pscustomobject]@{
        Name = $dir.Name
        PID = (dir IIS:\AppPools\$($dir.Name)\WorkerProcesses).ProcessId
    })
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM