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 OverflowAre you able to exit FastAPI/uvicorn via ctrl+c in Powershell on Windows?
Is there script to close application what using 8080 port automatically?
Videos
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.
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.
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?