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 OverflowStep 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.
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
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 4skips the first four header lines. (Selectis short forSelect-Objectused to perform SQL SELECT like projects of objects.%is short forForeach-Objectwhich 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 propertiesOriginalthe string fromnetstatandFieldsthe array just created.?is short forWhere-Objectwhich 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.
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.
Can I stop system processes on port 80 on Windows 10?
Killport - A Simple Script to Kill Processes on a Port
Is there a powershell way I can use to kill an open port, and maybe automate the process?
Kill “Port Already in Use” Errors Instantly with pf
Videos
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
I know this is an old thread, but in case anyone else is having the same issue, I had...
What may be happening is that your process had a TCP port open when it crashed or otherwise exited without explicitly closing it. Normally the OS cleans up these sorts of things, but only when the process record goes away. While the process may not appear to be running any more, there is at least one thing that can keep a record of it around, in order to prevent reuse of its PID. This is the existence of a child process that is not detached from the parent.
If your program spawned any processes while it was running, try killing them. That should cause its process record to be freed and the TCP port to be cleaned up. Apparently windows does this when the record is released not when the process exits as I would have expected.
Open command prompt as admin
- C:\WINDOWS\system32>netstat -ano | findstr :7895
*** Repeat step 2 until there are no more child process
C:\WINDOWS\system32>wmic process where (ParentProcessId=1091 ) get Caption,ProcessId
Caption ProcessId
cmd.exe 1328
2.a. C:\WINDOWS\system32>wmic process where (ParentProcessId=1328) get Caption,ProcessId
Caption ProcessId
conhost.exe 1128
2.b. repeat this until no further child processes found
-- Then kill all child processes
- C:\WINDOWS\system32>taskkill /F /PID 1128 SUCCESS: The process with PID 9500 has been terminated.
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?