How do I kill the process currently using a port on localhost in Windows?
Solution 1
Step 1:
Open up cmd.exe (note: you may need to run it as an administrator, but this isn't always necessary), then run the below command:
netstat -ano | findstr :<PORT>
(Replace <PORT>
with the port number you want, but keep the colon)
The area circled in red shows the PID (process identifier). Locate the PID of the process that's using the port you want.
Step 2:
Next, run the following command:
taskkill /PID <PID> /F
(No colon this time)
Lastly, you can check whether the operation succeeded or not by re-running the command in "Step 1". If it was successful you shouldn't see any more search results for that port number.
Solution 2
I know that is really old question, but found pretty easy to remember, fast command to kill apps that are using port.
Requirements: [email protected]^ version
npx kill-port 8080
You can also read more about kill-port here: https://www.npmjs.com/package/kill-port
Solution 3
Step 1 (same is in accepted answer written by KavinduWije):
netstat -ano | findstr :yourPortNumber
Change in Step 2 to:
tskill typeyourPIDhere
Note: taskkill
is not working in some git bash terminal
Solution 4
There are two ways to kill the processes
Option 01 - Simplest and easiest
Requirement : [email protected]^ version
Open the Command prompt as Administrator and give the following command with the port (Here the port is 8080)
npx kill-port 8080
Option 02 - Most commonly used
- Step 01
Open Windows command prompt as Administrator - Step 02
Find the PID of the port you want to kill with the below command: Here port is 8080
netstat -ano|findstr "PID :8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 18264
- Step 03
Kill the PID you received above with the below command (In my case PID is 18264)
taskkill /PID 18264 /f
Solution 5
With Windows 10 default tools:
- Step one:
Open Windows PowerShell as Administrator
- Step two:
Find PID (ProcessID) for port 8080:
netstat -aon | findstr 8080
TCP 0.0.0.0:8080 0.0.0.0:0 LISTEN 77777
- Step three:
Kill the zombie process:
taskkill /f /pid 77777
where "77777" is your PID
KavinduWije
Updated on February 02, 2022Comments
-
KavinduWije over 2 years
How can I remove the current process/application which is already assigned to a port?
For example:
localhost:8080
-
TripeHound over 6 years@HardikMandankaa Is it the same process? Some software may be set up to relaunch the listening process if it is killed.
-
Green over 6 years
'Stop-Process' is not recognized as an internal or external command,
-
morganpdx over 6 yearsI find that this works:
Stop-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess -Force
-
Robert about 6 yearsI had to enter escape characters when running taskkill:
taskkill //PID 12552 //F
-
Robert about 6 years@kylexy1357 try with a single slash. The "double slash" is an escape character that precedes the /, which is not needed for some shells
-
nurettin about 6 yearsaccepted answer will not work for services which are set up to restart on failure (this is not linux)
-
dxhans5 almost 6 yearsThis is the solution that worked for me. I'm using GIT Bash.
-
Mahesh Narwade almost 6 yearsIf you want to do it in a .bat, replace %a for %%a
-
Totty.js over 5 yearsI got processId 0 on port 80. If I try to kill it I get "ERROR: The process with PID 0 could not be terminated. Reason: This is critical system process. Taskkill cannot end this process."
-
Chemist over 5 yearsThe colon symbol has to be in a very specific place. Can't change spaces or this command won't work. Otherwise this also works without colon: "netstat -ano | findstr 8080"
-
vhs about 5 yearsIf you know the port is using IPv4 you can do an
lsof -nt -i4TCP:9001
as well. -
Serob_b over 4 yearsHow to automate the process and combine these two commands together in one bat file if there is no possibility to view the cmd output and then write new command manually?
-
Ashwani Panwar over 4 yearsWhat work for me is
taskkill //PID myProcessId -F
-
Vikrant over 4 years@Serob_b
set /p port="Enter port: "
-> Input portFOR /F "tokens=5" %%T IN ('netstat -aon ^| findstr %port% ') DO ( SET /A ProcessId=%%T) &GOTO SkipLine
:SkipLine
-> Extracts PID into variabletaskkill /f /pid %ProcessId%
-> Kills the taskcmd /k
-> Keep the window open -
VISQL about 4 years2020-04-03, Windows10, Python 3.6.6, using Git Bash: confirming that using the double forward slash worked for me as well. I needed to kill a Flask app process on
localhost:5000
that didn't terminate. e.g.taskkill //F //PID 16660
. -
peevesy about 4 yearsThis worked for a socket that uses a particular port number in Google Cloud as well! Thanks a ton
-
Marcin Kulik about 4 yearsi think you meant PID_NUMBER and not PORT_NUMBER in
taskkill /PID PORT_NUMBER /F
-
Dan Starns almost 4 yearsI know this works because I tested it, I'm trying to find documentation around it, do you have any?
-
lazycipher almost 4 years@DanStarns, I've found only this so far! docs.microsoft.com/en-us/windows/terminal
-
Dan Starns almost 4 yearsThanks for your time, it's not quite the page I'm looking for, a page with all the functions provided in the terminal such as
kill
. Ill post here if i find. -
lazycipher almost 4 yearsI haven't found much about this as of now. Please post if you find anything.
-
tscpp almost 4 yearsThis answer was the only one line command to work for me so it's really good. I have a task running on two ports which cause the error "ERROR: The process "6552" not found." because the task has already been exited.
-
Michael Elliott almost 4 yearsI can't believe I didn't know about this, so useful thank you!
-
CrazyVideoGamer almost 4 years@Vikrant Is there a way to hide all the commands and just show "Enter port: " and "SUCCESS: The process with PID 35264 has been terminated." ?
-
gunes almost 4 yearsI had to do kill -9 $(lsof -t -i :PORT_NUMBER)
-
VB_Dojnaz almost 4 years@CrazyVideoGamez
@echo off
-
Pranav Raut over 3 yearsEven if this is a correct answer. The question was asked for windows environment and your answer is invalid on a Linux system.
-
Eugene Beliaev over 3 yearsyayy, awesome way :)
-
gatsbyz over 3 yearslove u so much rn
-
Bharathiraja over 3 yearswith colon not working netstat -ano | findstr :<portNumber>, without colon working fine netstat -ano | findstr <portNumber>
-
FSCKur over 3 yearsI have to downvote because of your confusion about
kill
. It's NOTHING to do with your choice of terminal. As any fool knows, in PS you use Get-Command to understand what command you're running, and it shows you that, on Windows, kill is an alias for Stop-Process. On Linux it's not an alias but the native command. -
lazycipher over 3 years@FSCKur, I don't think it was already there earlier(talking about alias)! It's something new that I found. Thanks for letting me know about the alias thing. I'll mention this thing in the answer.
-
FSCKur over 3 yearsAppreciated; sorry about my previous sharp tone. However, there's still confusion between terminal and shell. You have provided a Powershell answer. A user running bash in WT wouldn't get the same results. If you change "WT" to "PS" then your answer becomes correct... however, it's a PS community guideline to not use aliases in code or help, so I'd still not be happy.
-
Shardj about 3 yearsThank you, so much overkill in other answers. Literally just need this scripted
-
Timo about 3 yearsNeed really far scroll down to get a "programmatic" answer like this. BTw what is
tokens=5
? -
Basit almost 3 yearsLove it, Thanks for adding up in my knowledge
-
Admin almost 3 yearsThanks a lot, save my day!
-
elakioui over 2 yearsI used : netstat -ano to get the PID number and kill the process using : taskkill /PID <PID> /F .
-
Code Whisperer over 2 yearsUnnecessary comment but huzzah!
-
GorvGoyl over 2 yearsThe term 'lsof' is not recognized as a name of a cmdlet, function, script file
-
Namit Piriya over 2 yearswhat are the ano flag
-
Daniel over 2 yearsI can't believe I never scrolled down to see this... I have come to this SO page so many times when I forget the bash command... This is so much easier to remember
-
Chau Giang over 2 yearsI got the error:
bash: taskill: command not found
-
Italo Borssatto over 2 years@ChauGiang It seems a typo. Use
tskill
instead oftaskill
. -
sg28 over 2 yearsWorked like a Charm for killing the running port. Thank you
-
Rahul over 2 yearsAwesome, Hurrey
-
mbomb007 over 2 yearsI ran it in PowerShell, and
taskkill
needed to be run in an elevated shell. -
Code Cooker over 2 yearsthis one helped me! I'm on Win10 ~
-
FCA69 about 2 yearsNo need for CurrPorts. In windows 10+ you can use the Resource Monitor, more precisely its Network Tab. In the bottom pane, there is a section listing all the opened ports and the PID of the processes which are using these ports.
-
Cos almost 2 yearsWhere is the $PROFILE file?