Assuming this is a Windows 7 machine - and we're talking about batch scripts on the Windows command line.
Imagine I want to start and stop two different processes running in the background, and run things whilst they running in the background. For example:
START /B CMD /C tomcatA.bat
doSomeStuff
stopTomcatACmd
START /B CMD /C tomcatB.bat
doSomeStuff
stopTomcatBCmd
I'm trying to figure out how to implement the stopTomcatBCmd
. On a Linux machine you could just kill
the pid
.
My question is: How do I kill a specific process running in the background in Windows?
For stuff like this you can almost always find a utility you can use as part of the Sysinternals suite. In this case I would recommend PsKill: https://technet.microsoft.com/en-us/sysinternals/pskill
Usage: pskill [-t] [\\computer [-u username [-p password]]] <process ID | name>
example: pskill notepad
Mark's article discussing usage of PsList and PsKill: http://windowsitpro.com/systems-management/pslist-and-pskill
TaskKill should do the job. you can write in the exact name of the task to kill, i.e. to kill all firefox processes
C:\>Taskkill /IM firefox.exe /F
or you can check the PID of specific task by writing Tasklist, and then kill the task by mentioning its PID i.e.
C:\>Taskkill /PID 26356 /F
I think taskkill is what you're looking for. With it you can kill a running process by its ID or image name (name of the .exe file).
You can read a detailed usage explanation on this page: http://www.computerhope.com/taskkill.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With