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?




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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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