Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We currently have a few processes running with the same image name: w3wp.exe.

One of them has a memory leak, so until the dev guys plug that we're wanting to run a scheduled task to kill the process before the RAM runs out on the server.

I've been using:

taskkill /F /FI "MEMUSAGE gt 5000000" /IM "w3wp.exe"

That kills the process whenever memory usage is > 5GB. I've been running this as a scheduled task every 5 minutes.

This works, but it also kills the other instances of w3wp.exe. They're all running under NTAUTHORITY.

My question is, is there a way of isolating a single process from where multiple processes are running under the same image name?

Does anyone know of a better way to do this?



share|improve this question
up vote 1 down vote accepted

Try the following in a batch file:

@echo off
set tmpfile=%tmp%\tasklist~.txt

tasklist /FI "MEMUSAGE gt 5000000" | FIND "w3wp.exe" > "%tmpfile%"
for /F "tokens=2*" %%i in (%tmpfile%) do @taskkill /f /PID %%i

del %tmpfile%

Edit: actually, there is an even better way:

First, you need to isolate the app in its own apppool. Then you just issue the following command: %windir%\System32\inetsrv\appcmd.exe recycle apppool "MyApplicationPool"

(use %windir%\System32\inetsrv\appcmd.exe list apppool to get the name if necessary)

That should recycle the app gracefully (unless it's really stuck).

share|improve this answer
Awesome, that works really well. Thanks for that! – Michael May 18 '12 at 9:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.