Find and kill process on port
bash
# Find process on port 3000
lsof -ti:3000
# Kill process on port 3000
kill -9 $(lsof -ti:3000)
# One-liner to kill port
lsof -ti:3000 | xargs kill -9
Common ports
bash
# Kill common development ports
kill -9 $(lsof -ti:3000) # React/Next.js
kill -9 $(lsof -ti:8000) # Python/Django
kill -9 $(lsof -ti:8080) # Java/Spring
kill -9 $(lsof -ti:5000) # Flask/Express
Create alias
Add to ~/.zshrc
:
bash
# Kill process on port
alias killport="lsof -ti:\$1 | xargs kill -9"
# Usage: killport 3000
Alternative method
bash
# Using netstat (macOS)
sudo lsof -i :3000
sudo kill -9 <PID>
# Using ss (Linux)
ss -tulpn | grep :3000
kill -9 <PID>
No more "port already in use" errors! 🎯