SysadminGuide

How to kill the process using a port on Windows

On this page
  1. Step 1: find the PID holding the port
  2. Step 2: confirm what it is (before you kill it)
  3. Step 3: kill it
  4. The PowerShell one-liner
  5. When it behaves differently than you expect

Your dev server won't start, and Windows greets you with 'address already in use'. Something's squatting on the port, and the fix is to kill that process, not the port itself: run netstat -ano, find the LISTENING line for your port (say 8080), read the PID in the last column, then taskkill /PID number /F. Two commands, error gone. Below we walk through reading the netstat output, checking which program owns the PID before you kill anything (ten seconds well spent), the PowerShell one-liner for people who live in that shell, and the two cases that trip everyone up: admin rights and a port stuck in TIME_WAIT.

The short answer

Find the PID listening on the port with netstat -ano | findstr :8080, read it from the last column, then run taskkill /PID 1234 /F. The “address already in use” error clears the moment the process dies. PowerShell folks get it in one line.

netstat -anofind the PID
taskkill /Fstop it
2 cmdsport freed
Answer card showing netstat -ano to find the PID on a port, then taskkill to free it, on Windows.
Find the PID, kill the PID. The port is free the moment the process exits. PNG

Step 1: find the PID holding the port

Windows
netstat -ano | findstr :8080

That spits out one line per connection on the port. The one we care about is in the LISTENING state, and the number in the last column is the PID of the process holding it. Working a different port? Our kill process on a port generator drops your number straight into every command on this page, Windows and Unix, ready to copy.

Step 2: confirm what it is (before you kill it)

Never kill a PID blind. Check which program it is first:

Windows
tasklist /FI "PID eq 1234"

If it’s the dev server you forgot to stop, great. If it’s something you don’t recognize, we’d rather know that before force-stopping it. So would you.

Step 3: kill it

Windows
taskkill /PID 1234 /F

/F forces termination. Got “Access is denied”? The process isn’t yours; reopen the prompt as administrator and run it again. Here’s the whole sequence end to end:

Command Prompt showing netstat finding PID 1234 on port 8080, tasklist confirming node.exe, then taskkill terminating it.
Port to PID to kill. Confirm the program in the middle step. PNG

The PowerShell one-liner

Living in PowerShell anyway? Skip netstat entirely. Honestly, this is the version I reach for most days:

PowerShell
Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess | Stop-Process -Force

When it behaves differently than you expect

Two surprises, both common. A port in TIME_WAIT has no owning process to kill; the socket is just cooling down and clears on its own in a minute or two. Nothing to do but wait. 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" and read the last column of the LISTENING line: that's the PID. To see which program it actually is, run tasklist filtering on PID eq 1234. PowerShell users can skip all that; "Get-NetTCPConnection -LocalPort 8080" shows the owning process directly.

taskkill says "Access is denied". What now?

The process isn't yours: it belongs to another user or runs as a Windows service, so you need an elevated prompt. Reopen Command Prompt with Run as administrator and the same taskkill command goes through.

Is there a PowerShell one-liner?

Yes: "Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess | Stop-Process -Force". One line, and it finds the PID holding the port and kills the process.

The port shows TIME_WAIT, not LISTENING. Can I kill it?

No, and you don't need to. TIME_WAIT means no process holds the port anymore; the socket is just cooling down after closing, and it clears itself within a couple of minutes. Nothing to kill. Just wait.