How to Find and Kill a Process Using a Specific Port in Linux
Find which process is using a port with lsof -i or netstat, then kill it by PID — useful when 'Address already in use' blocks a server from starting.
Published September 21, 2026
Find the process holding a port with lsof -i :PORT (or ss -ltnp), then stop it with kill PID. Use kill -9 only if it ignores a normal kill.
The concept
Only one process can listen on a port at a time. 'Address already in use' means a previous process (often a crashed dev server) still holds it.
A normal kill sends SIGTERM, letting the program clean up. kill -9 sends SIGKILL, which cannot be caught and skips cleanup.
Find then stop
lsof -i :3000
COMMAND PID USER NAME
node 4821 ada *:3000 (LISTEN)
kill 4821
lsof -i :3000
(no output — port is free)
Practical examples
One-liner
kill $(lsof -t -i :3000)With ss (no lsof installed)
ss -ltnp | grep :3000Force kill
kill -9 4821fuser
fuser -k 3000/tcpCommon mistakes
- Using kill -9 first and leaving temp files or locks.
- Killing a system service you needed — check the command name.
- Forgetting sudo for processes owned by another user.
Key takeaways
- lsof -i :PORT or ss -ltnp find the PID.
- kill PID first, kill -9 last.
- Check what it is before killing.
FAQ
How do I do this on macOS?
The same lsof command works on macOS.
Why does the port stay busy after killing?
Sockets in TIME_WAIT can linger briefly; a new process can usually still bind with SO_REUSEADDR.