bash kill process by port number
Quick Answer
# macOS / Linux — find and kill by port
kill -9 $(lsof -t -i:8080)
# Linux alternative using fuser
fuser -k 8080/tcp
# Check what is on the port first
lsof -i :8080
# or
ss -tlnp | grep 8080
Usage
A development server is still running from a previous session and blocking the port.
Other causes & fixes
Find PID without killing
# Get PID(s) listening on port 3000
lsof -t -i:3000
# More detail: PID, process name, user
lsof -i :3000
# Linux: netstat alternative
ss -tlnp | grep :3000
Kill gracefully first, then force
pid=$(lsof -t -i:8080)
kill $pid # SIGTERM — graceful shutdown
sleep 2
kill -9 $pid 2>/dev/null || true # SIGKILL if still running
Multiple processes on the same port
# lsof -t returns multiple PIDs
lsof -t -i:8080 | xargs kill -9
Related