bash kill process on port 3000 or 8080

# macOS / Linux — kill the process listening on port 3000
kill -9 $(lsof -t -i:3000)

# Change 3000 to 8080, 8000, 5000, or any blocked port
kill -9 $(lsof -t -i:8080)

# Linux alternative using fuser
fuser -k 8080/tcp

# Check what is on the port first
lsof -i :3000
# or
ss -tlnp | grep :3000

A development server is still running from a previous session and blocking a port such as 3000, 8080, 8000, or 5000.

Find PID without killing the process

Start here when you want to see which command owns the port before killing it.

# 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

SIGTERM gives the process a chance to shut down cleanly. Use kill -9 only when the process ignores the normal signal.

pid=$(lsof -t -i:8080)
kill $pid           # SIGTERM — graceful shutdown
sleep 2
kill -9 $pid 2>/dev/null || true  # SIGKILL if still running

Kill every process using the same port

lsof can return multiple PIDs. Pipe them to xargs when a port has more than one listener or related process.

# lsof -t returns multiple PIDs
lsof -t -i:8080 | xargs kill -9

Git Bash on Windows: kill process by port

In Git Bash on Windows, lsof is usually not available. Use Windows netstat and taskkill from the same terminal.

# Find the PID using port 3000
netstat -ano | findstr :3000

# Replace 12345 with the PID from the last column
taskkill //PID 12345 //F