Cry about... .NET How to ...
How to identify the application pool for a worker process
Given that there is a worker process on a server which is consuming a lot of CPU time and that the server hosts more than one web-application, is there any way of identifying which web application the worker process is for?
Each worker process will belong to a single application pool, and it is possible to identify the application pool associated with a worker process. Since two or more applications can use the same application pool it is not directly possible to identify the application - but if you use a separate application pool for each web application then identifying the application pool should be sufficient to identify the process.
How to identify the worker process PID for each application pool
The method to identify the application pool has changed between IIS 6 and IIS 7.
On IIS 6
- Start a command window:
Start → Run...
type:cmd
a new command window should open.
- Enter:
cscript %windir%\system32\iisapp.vbs
This should produce output similar to the following (your output will be different, this is only included as an example):
C:> cscript %windir%\system32\iisapp.vbs
Microsoft (R) Windows Script Host 5.6. All rights reserved.
W3WP.exe PID: 5080 AppPoolId: ExchangeApplicationPool
W3WP.exe PID: 5812 AppPoolId: DefaultAppPool
C:>This will show the PID (process identifier) of each worker process and the name of the application pool that that worker process is serving.
On IIS 7
- Start a command window:
Start → Run...
type:cmd
a new command window should open.
- Enter:
%windir%\system32\appcmd.exe list wp
This should produce output similar to the following (your output will be different, this is only included as an example):
C:> %windir%\system32\appcmd.exe list wp
WP "5068" (applicationPool:file.types.explained.at)
WP "2244" (appliactionPool:newsgroups.archived.at)
WP "2232" (applicationPool:everything.explained.at)
C:>This will show the PID (process identifier) of each worker process and the name of the application pool that that worker process is serving.
Which worker process (and therefore pool) is busy?
Assuming you have a worker process (w3wp.exe
) which is
very busy, the next task is to obtain the PID of that worker process.
- Start "Task Manager"
There are several ways to start Task Manager, possibly the simplest is to right click on the start bar and select "Task Manager".
- Open the "Processes" tab.
If you have the option to "Show processes from all users" then select this, otherwise it will not list the worker processes. (This option did not exist in Windows XP and earlier.)
- There should be a column headed "Image Name" (this is the name of the process), click this to sort the processes by name.
- Scroll down the list until you find "w3wp.exe". There will be at most one for each application pool. (An application pool will not have a worker process if none of its applications are currently active - and each pool will recycle after a set time, so worker processes will gradually die unless they are required.)
- The default view in Task Manager does not show the "PID" of each
worker process. To show the PID:
view → Select Columns...
Check "PID (Process Identifier) and then click [OK]
Task Manager should now be showing you a list of all the worker processes (w3wp.exe) together with their PIDs. - Use the information you obtained earlier when you listed the worker process PIDs for each application pool to identify which application pool each worker process is associated with.
If you have a worker process which is using a lot of CPU then you can use this technique to identify the application pool and (hopefully) from there application.
These notes are believed to be correct for .NET 2 and .NET 3.5 (on Windows 2003 and 2008 server), and may apply to other versions as well.
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.