Kill a process using a specific port (MacOS)
Find what's holding a port and kill it:
1lsof -tiTCP:3000 -sTCP:LISTEN | xargs killlsof -t prints just PIDs; -iTCP:PORT -sTCP:LISTEN narrows to listeners on that port so you don't catch unrelated UDP or established connections. Default kill sends SIGTERM — the process gets a chance to clean up. Only escalate to kill -9 (SIGKILL) if it's stuck; SIGKILL skips cleanup and can corrupt sockets, lockfiles, or in-flight DB writes.
If the process is owned by another user or on a privileged port (<1024), prefix with sudo. On macOS Monterey+, ports 5000 and 7000 are taken by AirPlay Receiver / Control Center — disable them in System Settings → General → AirDrop & Handoff if you need those ports back.
Related:
1lsof -iTCP -sTCP:LISTEN -nP # every listening TCP port
2pgrep -fl <name> # PID by process name
3pkill -f <name> # kill by process name
4npx kill-port 3000 # cross-platform alternative