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.

Answer from KavinduWije on Stack Overflow
Top answer
1 of 4
12

Is there any thing like a pipe or similar that I can use on Windows OS to run this command in one line?

Both cmd.exe and PowerShell support pipes from one command to another. In PowerShell something like (this should be on a single line on the command line, or use ` to escapte newlines in a script):

netstat -ano
 | select -skip 4 
 | % {_ -split ' {3,}'; New-Object 'PSObject' -Property @{Original=$_;Fields=$a}} 
 | ? {$_.Fields[1] -match '15120$'}
 | % {taskkill /F /PID $_.Fields[4] }

Where:

  • Select -skip 4 skips the first four header lines. (Select is short for Select-Object used to perform SQL SELECT like projects of objects.
  • % is short for Foreach-Object which performs a script block on each object ($_) in the pipeline and outputs the results of the script block to the pipeline. Here it is first breaking up the input into an array of fields and then creating a fresh object with two properties Original the string from netstat and Fields the array just created.
  • ? is short for Where-Object which filters based on the result of a script block. Here matching a regex at the end of the second field (all PowerShell containers a zero based).

(All tested except the last element: I don't want to start killing processes :-)).

In practice I would simplify this, eg. returning just 0 or the PID from the first foreach (which would be designed to ignore the headers) and filter on value not zero before calling taskkill. This would be quicker to type but harder to follow without knowing PowerShell.

2 of 4
3

Open command prompt and execute:

for /f "tokens=5" %a in ('netstat -aon | find "8080"') do taskkill /f /pid %a

If you want to do it in a batch file instead, replace %a with %%a and | with ^|.

If you just want to kill the one that is listening on that port append | find "LISTENING" at the end of the other find.

Discussions

Can I stop system processes on port 80 on Windows 10?
What issue or error are you experiencing? When I checked port 80 there were approx 10 processes, mostly Chrome & Edge browses processes. When I closed those, only 4 system processes on port 80. I am trying to initiate my site via site domains. My domain is not active other than being registered ... More on community.localwp.com
🌐 community.localwp.com
0
0
January 9, 2024
Killport - A Simple Script to Kill Processes on a Port
I wrote this up and got distracted for the last few hours... I really, really like the simplicity! At the risk of ruining that, however, I wonder if it may be useful/wise to have a confirmation option like rm's -i? You may also like to check whether the user has the ability to kill the target proc and if not, look at launching sudo. Or just outright restrict it to root/sudo only. #!/bin/bash set -euo pipefail It's been a while since I've had to say this: Standard Warning about The Unofficial Strict Mode. readonly os=$(uname) https://www.shellcheck.net/wiki/SC2155 You may also like to look at $OSTYPE kill_port() { local port=$1 https://www.shellcheck.net/wiki/SC2155 ... probably.... You may like to consider something like port="${1:?No port defined}" to have a degree of auto-failure. It's not strictly necessary in this case, but a good habit to get into nonetheless. # Validate the port number if ! [[ "$port" =~ ^[0-9]{1,5}$ && "$port" -ge 0 && "$port" -le 65535 ]]; then echo "Invalid port number" exit 1 fi There's a bit going on here. Firstly, I would split this out into separate checks like this: printf -- '%d' "${port}" >/dev/null 2>&1 || { printf -- '%s\n' "Given port is not an integer" >&2 exit 1 } (( port > 0 && port <= 65535 )) || { printf -- '%s\n' "Given port must be between 1 and 65535" >&2 exit 1 } If the script got much bigger, you'd want to implement a die() function, so those would look more like printf -- '%d' "${port}" >/dev/null 2>&1 || die "Given port is not an integer" (( port > 0 && port <= 65535 )) || die "Given port must be between 1 and 65535" Note that I use printf. echo is a portability mess and POSIX specifies that you should use printf for that reason - they decided that echo was unfixable. Fun fact: echo in Apple's default bash is different from echo in the same version of bash on Linux. When you use echo, what you're doing is inflicting unpredictable behaviour on consumers of your code. Note also that these are error messages, so we send them to stderr. # Check if port is in use if ! type lsof >/dev/null 2>&1 || ! lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null; then echo "Port $port is not in use" exit 1 fi The more common way to check if a command exists is command -v rather than type/which/hash/-x # Kill the process if [ "$os" == "Darwin" ]; then # macOS lsof -ti tcp:"$port" | xargs kill else # Linux fuser -k "$port"/tcp fi == is best reserved for arithmetic contexts IMHO, and within single square brackets it's not a specified behaviour. Use = for string comparisons in [[]] and == for arithmetic comparisons in (()). Generally speaking. Consider a case statement instead. You can see examples of $OSTYPE in a case statement here Linux often has lsof too, you may also like to look at netstat and/or ss echo "Process on port $port killed" } # Check if port is provided if [ $# -ne 1 ]; then echo "usage: killport " exit 1 fi I would put this right towards the top of the script. You want a script to fail fast, fail early: so fail out before declaring any vars, functions etc. kill_port "$1" exit 0 Nice. More on reddit.com
🌐 r/bash
11
28
February 16, 2023
Is there a powershell way I can use to kill an open port, and maybe automate the process?
Use Get-NetTCPConnection | select LocalPort,OwningProcess to find out the process ID. Then use Stop-Process -Force -Id to force terminate that process. Make sure you're running as admin. More on reddit.com
🌐 r/PowerShell
5
0
October 4, 2019
Kill “Port Already in Use” Errors Instantly with pf
Do people not know you can make functions? Good on you for the package but jeez lol kill_port() { if [ -z "$1" ]; then echo "Usage: kill_port " return 1 fi PORT=$1 PID=$(lsof -ti tcp:$PORT) if [ -z "$PID" ]; then echo "No process found running on port $PORT." return 1 fi echo "Killing process $PID on port $PORT..." kill -9 $PID && echo "Killed." } More on reddit.com
🌐 r/golang
16
32
June 5, 2025
🌐
DEV Community
dev.to › osalumense › how-to-kill-a-process-occupying-a-port-on-windows-macos-and-linux-gj8
How to Kill a Process Occupying a Port on Windows, macOS, and Linux - DEV Community
September 19, 2024 - Here, 1234 is the PID of the process using port 5672. Killing the Process To kill the process, use the taskkill command with the PID obtained above. ... Replace 1234 with the actual PID.
🌐
Quora
quora.com › How-do-I-stop-port-8080-in-Windows
How to stop port 8080 in Windows - Quora
Answer: First of all, you need to find which process open the port. Run this command: [code ]netstat -aon | findstr 8080[/code] Then you will see something like this The number 9260 is the process ID owning the port 8080. Or should we say the process 9260 is the one listening on port 8080. Th...
🌐
Sentry
sentry.io › sentry answers › windows › kill process using port in windows
Kill process using port in Windows | Sentry
The final number on both lines is the process ID (PID) of the process using port 8080. Using this PID, we can end the process with taskkill: ... The /PID flag indicates that we’re locating the task to kill by PID, and the /F flag will forcefully ...
🌐
VPSMakers
vpsmakers.com › home › windows › how kill a process running on a port in windows?
How Kill A Process Running On A Port In Windows - VPSMakers
April 23, 2024 - Follow our step-by-step instructions ... PID you want to free up. step 3: Kill the Process: In this step, the taskkill command followed by the PID and F flag, forces the process to terminate....
🌐
Microsoft Learn
learn.microsoft.com › en-us › troubleshoot › windows-server › performance › determine-which-program-use-block-tcp-ports
How to determine which program uses or blocks specific TCP ports in Windows Server 2003 - Windows Server | Microsoft Learn
February 12, 2026 - If you use Task Manager, you can match the process ID that is listed to a process name (program). With this feature, you can find the specific port that a program currently uses. Because a program already uses this specific port, another program is prevented from using that same port.
Find elsewhere
🌐
Local
community.localwp.com › support
Can I stop system processes on port 80 on Windows 10? - Support - Local Community
January 9, 2024 - What issue or error are you experiencing? When I checked port 80 there were approx 10 processes, mostly Chrome & Edge browses processes. When I closed those, only 4 system processes on port 80. I am trying to initiate my site via site domains. My domain is not active other than being registered ...
🌐
Reddit
reddit.com › r/bash › killport - a simple script to kill processes on a port
r/bash on Reddit: Killport - A Simple Script to Kill Processes on a Port
February 16, 2023 -

Have you ever encountered the issue of not being able to start a process because the port is already in use? Killport is a simple script that allows you to quickly kill any process running on a specified port.

Using Killport is easy. Simply provide the port number as a command-line argument and the script will automatically find and kill any process running on that port. The script works on both macOS and Linux, and it is easy to install.

killport

Give it a try and let me know what you think.

give a ✨ star, if you liked it. Github

Top answer
1 of 5
3
I wrote this up and got distracted for the last few hours... I really, really like the simplicity! At the risk of ruining that, however, I wonder if it may be useful/wise to have a confirmation option like rm's -i? You may also like to check whether the user has the ability to kill the target proc and if not, look at launching sudo. Or just outright restrict it to root/sudo only. #!/bin/bash set -euo pipefail It's been a while since I've had to say this: Standard Warning about The Unofficial Strict Mode. readonly os=$(uname) https://www.shellcheck.net/wiki/SC2155 You may also like to look at $OSTYPE kill_port() { local port=$1 https://www.shellcheck.net/wiki/SC2155 ... probably.... You may like to consider something like port="${1:?No port defined}" to have a degree of auto-failure. It's not strictly necessary in this case, but a good habit to get into nonetheless. # Validate the port number if ! [[ "$port" =~ ^[0-9]{1,5}$ && "$port" -ge 0 && "$port" -le 65535 ]]; then echo "Invalid port number" exit 1 fi There's a bit going on here. Firstly, I would split this out into separate checks like this: printf -- '%d' "${port}" >/dev/null 2>&1 || { printf -- '%s\n' "Given port is not an integer" >&2 exit 1 } (( port > 0 && port <= 65535 )) || { printf -- '%s\n' "Given port must be between 1 and 65535" >&2 exit 1 } If the script got much bigger, you'd want to implement a die() function, so those would look more like printf -- '%d' "${port}" >/dev/null 2>&1 || die "Given port is not an integer" (( port > 0 && port <= 65535 )) || die "Given port must be between 1 and 65535" Note that I use printf. echo is a portability mess and POSIX specifies that you should use printf for that reason - they decided that echo was unfixable. Fun fact: echo in Apple's default bash is different from echo in the same version of bash on Linux. When you use echo, what you're doing is inflicting unpredictable behaviour on consumers of your code. Note also that these are error messages, so we send them to stderr. # Check if port is in use if ! type lsof >/dev/null 2>&1 || ! lsof -Pi :"$port" -sTCP:LISTEN -t >/dev/null; then echo "Port $port is not in use" exit 1 fi The more common way to check if a command exists is command -v rather than type/which/hash/-x # Kill the process if [ "$os" == "Darwin" ]; then # macOS lsof -ti tcp:"$port" | xargs kill else # Linux fuser -k "$port"/tcp fi == is best reserved for arithmetic contexts IMHO, and within single square brackets it's not a specified behaviour. Use = for string comparisons in [[]] and == for arithmetic comparisons in (()). Generally speaking. Consider a case statement instead. You can see examples of $OSTYPE in a case statement here Linux often has lsof too, you may also like to look at netstat and/or ss echo "Process on port $port killed" } # Check if port is provided if [ $# -ne 1 ]; then echo "usage: killport " exit 1 fi I would put this right towards the top of the script. You want a script to fail fast, fail early: so fail out before declaring any vars, functions etc. kill_port "$1" exit 0 Nice.
2 of 5
3
Now try killing nfs/portmapper or wireguard :D Hint: You can't. Reason: When the kernel opens the socket there will be no pid attached to that process and you will have no way to kill it because of that. You can try that by configuring a wireguard interface. You will see that neither netstat/ss/lsof or /proc/*/fd/ be able to find that inode or pid.
🌐
Linux Hint
linuxhint.com › kill-process-currently-using-port-localhost-windows
How to Kill the Process Currently Using a Port on localhost in Windows – Linux Hint
... First, press the “Window+R” key to open the Run box. Type “cmd” in the dropdown menu and hit the “OK” button to open a command prompt: ... Then, use the “taskkill” command and specify the PID of the process currently running on localhost and kill it:
🌐
DEV Community
dev.to › smpnjn › how-to-kill-a-process-running-on-a-port-3pdf
How to Kill a Process Running on a Port - DEV Community
September 18, 2022 - The PID can be found at the end of the line when you run this process: ... Then, similar to linux and mac, kill what is on that port, replacing PID with the PID for that process from the statement above.
🌐
Reddit
reddit.com › r/powershell › is there a powershell way i can use to kill an open port, and maybe automate the process?
r/PowerShell on Reddit: Is there a powershell way I can use to kill an open port, and maybe automate the process?
October 4, 2019 -

I've been having an issue with my IDE, that it's keeping open a port sometimes when I think it's closed. I'd like to be able to kill it by just typing in something and the port number, and I was wondering if there was a way to set this up in Powershell?

🌐
danvega.dev
danvega.dev › blog › windows-kill-process-by-port-number
Windows Kill Process By Port Number
April 16, 2015 - I am doing a lot of Java development these days and I have about 5 different applications that I may fire up during a day and because they all run on my local machine most of them use port 8080 by default. Once in a while, I will forget to kill an application. When I try and start another application I will receive this error. If you need to kill a process manually on Windows it's actually pretty easy.
🌐
Code4IT
code4it.dev › blog › kill-the-process-blocking-a-port-windows
How to kill a process running on a local port in Windows | Code4IT
January 16, 2024 - Now that we have the Process ID ... instance of Visual Studio running an API application. We can now kill the process by hitting End Task....
🌐
Medium
medium.com › eat-sleep-code-repeat › how-to-force-kill-a-windows-process-running-on-port-8080-e3a3b2ce3183
How to Force Kill a windows process running on port 8080 | by gautham | Eat-Sleep-Code-Repeat | Medium
August 27, 2020 - 2. Run this netstat command to find what service or process is running on port 8080 ... 3. To force kill the process , run the following command with the pid that you got from the netstat command above.
🌐
Technipages
technipages.com › home › how to kill a process on a port on windows 11: 5 best ways
How to Kill a Process on a Port on Windows 11 - Technipages
May 3, 2023 - Then, find the task in Task Manager under the Processes column. ... Right-click the process and choose End task from the context menu that pops up. That’s it! You’ve cleared the occupied port by ending the process linked to it from Task Manager.