Problem
You want a quick way to kill a process on your system, or kill and restart an ASP.NET or IIS worker process.
Solution
Windows has two built-in command-line utilities that you can use to help with this: Tasklist and Taskkill.
Within a command-line window you can type "Tasklist" to obtain a listing of all of running Windows processes on your system:
C:\Documents and Settings\Arun>tasklist
Image Name PID Session Name Session# Mem Usage
========================= ====== ================ ======== ============
System Idle Process 0 Console 0 16 K
System 4 Console 0 212 K
smss.exe 824 Console 0 372 K
csrss.exe 876 Console 0 5,116 K
winlogon.exe 900 Console 0 3,848 K
services.exe 944 Console 0 4,112 K
lsass.exe 956 Console 0 1,772 K
svchost.exe 1372 Console 0 22,240 K
svchost.exe 1524 Console 0 3,428 K
svchost.exe 1572 Console 0 4,916 K
spoolsv.exe 1788 Console 0 5,660 K
inetinfo.exe 352 Console 0 9,860 K
sqlservr.exe 612 Console 0 7,348 K
sqlservr.exe 752 Console 0 15,552 K
explorer.exe 2960 Console 0 25,224 K
CTHELPER.EXE 3660 Console 0 4,964 K
LVComS.exe 872 Console 0 3,092 K
msmsgs.exe 3596 Console 0 6,532 K
sqlmangr.exe 3096 Console 0 4,264 K
OUTLOOK.EXE 1740 Console 0 75,992 K
iexplore.exe 472 Console 0 37,372 K
cmd.exe 732 Console 0 2,436 K
tasklist.exe 3104 Console 0 4,156 K
wmiprvse.exe 3776 Console 0 5,416 K
TaskKill can then be used to terminate any process instance in the above list. Simply provide it with the PID (Process ID) value of the process instance to kill and it will terminate it:
C:\Documents and Settings\Scott>taskkill /pid 1980
SUCCESS: The process with PID 1980 has been terminated.
ASP.NET on Windows 2000 and XP runs code within the "aspnet_wp.exe" worker process (when using IIS). On Windows 2003 it runs within the IIS6 "w3wp.exe" worker process. Both of these processes are launched from Windows system services, which means you must provide the "/F" switch to taskkill to force-terminate them:
C:\Documents and Settings\Scott>tasklist
Image Name PID Session Name Session# Mem Usage
========================= ====== ================ ======== ============
aspnet_wp.exe 3820 Console 0 13,512 K
C:\Documents and Settings\Scott>taskkill /pid 3820 /F
SUCCESS: The process with PID 3820 has been terminated.
As a short-cut, you can also just provide the process image name to "Taskkill" if you want to avoid having to lookup the PID value for a specific process instance. For example, the below command will kill all ASP.NET worker processes on the system:
C:\Documents and Settings\Scott>taskkill /IM aspnet_wp.exe /F
SUCCESS: The process "aspnet_wp.exe" with PID 2152 has been terminated.
ASP.NET and IIS will automatically launch a new worker process the next time a request is received by the system. So when you run the above command it will shutdown all active ASP.NET Worker processes. When you then hit the site again a new one will be automaticlaly launched for it (and it will have a new PID as a result).
Note that both TaskList and TaskKill support a "/S" switch that allows you to specify a remote system to run the commands against. If you have remote admin rights on one of your co-workers machines this can be a lot of fun.
Thanks & Regards,
Arun Manglick
SMTS || Microsoft Technology Practice || Bridgestone - Tyre Link || Persistent Systems || 3023-6258
DISCLAIMER ========== This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.
No comments:
Post a Comment