Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get IIS AppPool Worker Process ID

Tags:

I have a PowerShell script that is run automatically when our monitoring service detects that a website is down. It is supposed to stop the AppPool (using Stop-WebAppPool -name $AppPool;), wait until it is really stopped and then restart it.

Sometimes it the process does not actually stop, manifested by the error

Cannot Start Application Pool:   The service cannot accept control messages at this time. (Exception from HRESULT: 0x80070425)" 

when you try to start it again.

If it takes longer than a certain number of seconds to stop (I will chose that amount of time after I have timed several stops to see how long it usually takes), I want to just kill the process.

I know that I can get the list of processes used by workers in the AppPool by doing dir IIS:\AppPools\MyAppPool\WorkerProcesses\,

Process ID  State      Handles  Start Time ----------  -----      -------  ---------- 7124        Running 

but I can't figure out how to actually capture the process id so I can kill it.

like image 704
yakatz Avatar asked Aug 10 '11 16:08

yakatz


People also ask

How do I find the IIS process ID?

Open IIS and in the Connections panel select the server node. In Features View double click the Worker Processes and based on the Application Pool Name you will be able to determine the Process Id required. Go back to the Task Manager and match the Process Id you found in IIS with the PID in Task Manager.

How do I find my worker process in IIS?

Open IIS manager and on the left side click on the name of your computer. You will then see a similar list of icons on the right as shown in the screenshot below. Double click on "Worker Processes" and you can get a list of which processes are currently running, here you can find your second process.

How do I find my w3wp process ID?

Open the Windows Task Manager, ensure that the PID and Command Line columns are shown on the screen. For all w3wp.exe processes, check the value of the Command Line argument. Find the w3wp.exe process that has the target application pool name mentioned in the Command Line column.

What is PID in IIS?

Applications running in an IIS worker process (w3wp.exe) consume resources on the server and there are times when investigation to correlate the process ID (PID) to the application pool where the application is hosted is needed to understand the application consuming the resources.


2 Answers

In case that Process ID is really the id of process to kill, you can:

$id = dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | Select-Object -expand processId Stop-Process -id $id 

or

dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | % { Stop-Process -id $_.processId } 
like image 122
stej Avatar answered Sep 20 '22 05:09

stej


In Command Prompt on the server, I just do the following for a list of running AppPool PIDs so I can kill them with taskkill or Task Mgr:

cd c:\windows\system32\inetsrv appcmd list wp 

taskkill /f /pid *PIDhere* 
like image 24
PandaCookie Avatar answered Sep 22 '22 05:09

PandaCookie