When a port is already in use on Windows, the fix is to find the process holding it and kill that process, not the port itself. Run netstat -ano to list every connection with its owning PID, pick out the line for your port (say 8080) in the LISTENING state, then run taskkill /PID number /F to stop it. Two commands and the 'address already in use' error is gone. Here's how to read the netstat output, how to confirm which program the PID belongs to before you kill anything, a one-line PowerShell version for the people who live in that shell, and the cases (admin rights, a port stuck in TIME_WAIT) where it behaves differently than you would expect.
The short answer
Find the PID listening on the port with
netstat -ano | findstr :8080, read the PID from the last column, then run
taskkill /PID 1234 /F. The “address already in use” error clears
immediately. In PowerShell it is a single line.
Step 1: find the PID holding the port
netstat -ano | findstr :8080 You get one line per connection on that port. The one you want is in the LISTENING state, and the number in the last column is the PID of the process holding the port.
Step 2: confirm what it is (before you kill it)
Never kill a PID blind. Check which program it is first:
tasklist /FI "PID eq 1234" If it is the dev server you forgot to stop, great. If it is something you do not recognize, that is worth knowing before you force-stop it.
Step 3: kill it
taskkill /PID 1234 /F /F forces termination. If you get “Access is denied”, the process is not
yours; reopen the prompt as administrator. Here is the whole sequence end to
end:
The PowerShell one-liner
If you prefer PowerShell, skip netstat entirely and do it in one line:
Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess | Stop-Process -Force When it behaves differently than you expect
Two common surprises. A port in TIME_WAIT has no owning process to kill; it clears on its own in a minute or two. And “Access is denied” always means the same thing here: the process belongs to another user or a service, so run the prompt as administrator.
On Linux or macOS instead? The tools are lsof and kill: see how to
kill the process using a port on Linux.
Frequently asked questions
How do I find which process is using a port on Windows?
Run "netstat -ano | findstr :8080". The last column of the LISTENING line is the PID. Match it to a program with tasklist, filtering on PID eq 1234. In PowerShell, "Get-NetTCPConnection -LocalPort 8080" shows the owning process directly.
taskkill says "Access is denied". What now?
The process belongs to another user or runs as a Windows service, so you need an elevated prompt. Reopen Command Prompt with Run as administrator and run the taskkill command again.
Is there a PowerShell one-liner?
Yes: "Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess | Stop-Process -Force". It finds the PID holding the port and kills the process in a single line.
The port shows TIME_WAIT, not LISTENING. Can I kill it?
No, and you do not need to. TIME_WAIT means no process holds the port; the socket is just cooling down after closing and it clears itself within a couple of minutes. There is nothing to kill, only to wait for.