Find and kill the process using a port

Fix "address already in use" / EADDRINUSE errors by finding which program is listening on a port, stopping it safely, and confirming the port is free.

5 steps⏱ 5 minBeginnerLinux · macOS · Windows✓ Verified 4 Nov 2026

Showing commands for This recipe doesn't cover this OS yet.

A dev server failing with EADDRINUSE, address already in use or port is already allocated means another process is already listening on that port. Often it’s an old copy of the same server.

Find what’s listening on the port

Linuxbash
sudo ss -ltnp 'sport = :3000'
LinuxExpected output
State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
LISTEN  0       511     0.0.0.0:3000         0.0.0.0:*          users:(("node",pid=12345,fd=21))
macOSzsh
lsof -nP -iTCP:3000 -sTCP:LISTEN
macOSExpected output
COMMAND   PID   USER   FD   TYPE  DEVICE  SIZE/OFF NODE NAME
node    12345   you    21u  IPv4  0x...      0t0  TCP *:3000 (LISTEN)
WindowsPowerShell
Get-NetTCPConnection -LocalPort 3000 -State Listen |
  Select-Object LocalAddress, LocalPort, OwningProcess,
    @{ Name = 'ProcessName'; Expression = { (Get-Process -Id $_.OwningProcess).ProcessName } }
WindowsExpected output
LocalAddress LocalPort OwningProcess ProcessName
------------ --------- ------------- -----------
::                3000         12345 node

Nothing to run on for this part.

Copy the PID into Your values → Process ID. Nothing printed? Then nothing is listening on that port. Check that you have the right port number.

On Linux, lsof -nP -iTCP:3000 -sTCP:LISTEN works too, if lsof is installed.

Check what that process is

Make sure you’re not about to stop something important, like a database or a system service.

Linux · macOSbash
ps -p 12345 -o pid,user,command
WindowsPowerShell
Get-Process -Id 12345 | Format-List Id, ProcessName, Path, StartTime

Nothing to run on for this part.

Stop it politely

This asks the process to shut down cleanly.

Linux · macOSbash
kill 12345
# use: sudo kill 12345  if it belongs to another user
WindowsPowerShell
Stop-Process -Id 12345

Nothing to run on for this part.

Force it if it won’t stop

Only use this if the polite stop didn’t work. The process gets no chance to save its work.

Linux · macOSbash
kill -9 12345
WindowsPowerShell
Stop-Process -Id 12345 -Force

Nothing to run on for this part.

Confirm the port is free

Run step 1’s command again. No output means the port is free. Now restart your server.

Linuxbash
sudo ss -ltnp 'sport = :3000'
macOSzsh
lsof -nP -iTCP:3000 -sTCP:LISTEN
WindowsPowerShell
Get-NetTCPConnection -LocalPort 3000 -State Listen -ErrorAction SilentlyContinue

Nothing to run on for this part.

Going further: one-liners

Find and stop whatever is listening on the port in one go. Be careful: this skips step 2’s check.

Linux · macOSbash
lsof -t -iTCP:3000 -sTCP:LISTEN | xargs kill
WindowsPowerShell
Get-NetTCPConnection -LocalPort 3000 -State Listen |
  ForEach-Object { Stop-Process -Id $_.OwningProcess }

Nothing to run on for this part.

Troubleshooting

The process comes straight back: a supervisor is restarting it, such as systemd, Docker, pm2, nodemon or a Windows service. Stop it at that level instead, e.g. docker ps then docker stop <name>, or sudo systemctl stop <service>.

Windows shows PID 0 or 4: that’s the System process (e.g. http.sys, which serves IIS). Don’t kill it. Change your app’s port instead, or stop the Windows service that registered the port.

Operation not permitted / Access is denied: the process belongs to another user. Use sudo (Linux/macOS) or an Administrator PowerShell (Windows).

Sources

Commands checked against these official sources on 4 Nov 2026. Found something out of date? Open an issue.

  1. lsof(8) manual page · lsof project
  2. ss(8) manual page · iproute2 project
  3. Get-NetTCPConnection (NetTCPIP) · Microsoft Learn
  4. Stop-Process · Microsoft Learn