Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I kill a specific process running in the background from the command prompt?

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?

like image 727
hawkeye Avatar asked Mar 04 '15 11:03

hawkeye


3 Answers

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

like image 148
Christian Hagelid Avatar answered Sep 18 '22 04:09

Christian Hagelid


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
like image 38
Anum Sheraz Avatar answered Sep 19 '22 04:09

Anum Sheraz


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

like image 21
Sledge Hammer Avatar answered Sep 19 '22 04:09

Sledge Hammer