41

Kill tomcat service running on any port, Windows using command promt like 8080/ 8005

Suraj Shingade
  • 2,134
  • 4
  • 17
  • 24

3 Answers3

127

1) Go to (Open) Command Prompt (Press Window + R then type cmd Run this).

2) Run following commands

For all listening ports

netstat -aon | find /i "listening"

Apply port filter

netstat -aon |find /i "listening" |find "8080"

Finally with the PID we can run the following command to kill the process

3) Copy PID from result set

taskkill /F /PID

Ex: taskkill /F /PID 189

Sometimes you need to run Command Prompt with Administrator privileges

Done !!! you can start your service now.

Suraj Shingade
  • 2,134
  • 4
  • 17
  • 24
  • very useful - coming from ease of using linux shell commands *to* windows .... above command have been very useful – exexzian Feb 01 '18 at 15:49
  • 2
    Or you could go a bit unnecessarily mad and put it all together on one line like so (adjust for port number!) `for /f "skip=1 tokens=5" %1 in ('netstat -aon ^| find "8080"') do taskkill /F /PID %1` – Scala Enthusiast Apr 27 '18 at 08:35
  • 1
    @ScalaEnthusiast I would gladly do that if I was comfortable in batch scripting. To me it seems more complex. – Paramvir Singh Karwal Dec 25 '18 at 10:31
  • 1
    I would add a double colon in front of the port to prevent an accidental lookup in the PID column. So: `for /f "skip=1 tokens=5" %1 in ('netstat -aon ^| find ":8080"') do taskkill /F /PID %1` – dforce May 20 '19 at 14:48
5
netstat -ano | findstr :3010

enter image description here

taskkill /F /PID

enter image description here

But it won't work for me

then I tried taskkill -PID <processorid> -F

Example:- taskkill -PID 33192 -F Here 33192 is the processorid and it works enter image description here

VIKAS KOHLI
  • 8,164
  • 4
  • 50
  • 61
1

Based on all the info on the post, I created a little script to make the whole process easy.

@ECHO OFF
netstat -aon |find /i "listening"

SET killport=
SET /P killport=Enter port: 
IF "%killport%"=="" GOTO Kill

netstat -aon |find /i "listening" | find "%killport%"

:Kill
SET killpid=
SET /P killpid=Enter PID to kill: 
IF "%killpid%"=="" GOTO Error

ECHO Killing %killpid%!
taskkill /F /PID %killpid%

GOTO End
:Error
ECHO Nothing to kill! Bye bye!!
:End

pause
Piyush Bansal
  • 101
  • 1
  • 4