Monday, June 4, 2012

Stopping a windows process


If you ever find yourself stuck (I was) with working on an old windows box and you dont have the benefits of using something better than the lame windows process explorer, here are some things that helped me out with force killing my process..


There were multiple instances of tomcat running on this box and there was no way to tell which .exe process belongs to the one I'm trying to stop.
To list just the tomcat instances, you could run the 'tasklist' command.


tasklist /fi "imagename eq tomcat5.exe"  (replace tomcat5.exe with whatever process you're looking for)




Now which one of those tomcat5.exe is mine?!!! 
Its ugly, but 'wmic' command would help you out to find out the specific tomcat5.exe process. 


wmic /output:C:\Processes.txt PROCESS get Caption,Commandline,Processid


This creates a Processes.txt file under C:\ which lists out all the processes and the binary executable path it was started from. 
After looking up this file, I was able to narrow it down to the specific PID 3868 and was able to kill it by running 


taskkill /f /pid 3868 


With something like Sysinternals Process Explorer, you wouldn't need to go through all this, but if you ever get stuck with some limitations.. then you could always use 'other' ways to get around! :)