Table of Contents
The Quick Way: One Command
With portrm, killing a process on any port takes one command:
$ ptrm fix 3000
Port 3000 in use
Node.js (PID 7821) - Express server
SAFE - dev server, safe to kill
Fix port 3000? [Y/n] Y
Killed PID 7821 (SIGTERM)
Port 3000 is now free
Skip confirmation: ptrm fix 3000 -y
Kill and restart: ptrm fix 3000 --run "npm start"
Kill multiple ports: ptrm fix 3000 8080 5432 -y
Install: npm install -g portrm or brew install abhishekayu/tap/portrm
macOS: Find and Kill Process on Port
Find what is using a port
$ lsof -i :3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 7821 user 23u IPv6 0x... 0t0 TCP *:3000 (LISTEN)
Or get just the PID:
$ lsof -ti :3000
7821
Kill the process
$ kill -9 $(lsof -ti :3000)
Or step by step:
$ kill 7821 # graceful (SIGTERM)
$ kill -9 7821 # force (SIGKILL) if SIGTERM fails
Linux: Find and Kill Process on Port
Using lsof
$ lsof -i :3000
$ kill -9 $(lsof -ti :3000)
Using fuser
$ fuser 3000/tcp # shows PID
$ fuser -k 3000/tcp # kills it
Using ss + kill
$ ss -tlnp | grep :3000
LISTEN 0 511 *:3000 *:* users:(("node",pid=7821,fd=23))
$ kill -9 7821
Windows: Find and Kill Process on Port
> netstat -ano | findstr :3000
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 7821
> taskkill /PID 7821 /F
PowerShell alternative:
> Get-NetTCPConnection -LocalPort 3000 | Select-Object OwningProcess
> Stop-Process -Id 7821 -Force
Common Ports and What Uses Them
| Port | Common Service | Kill Command |
|---|---|---|
| 3000 | React, Next.js, Express | ptrm fix 3000 |
| 3001 | React (alternate) | ptrm fix 3001 |
| 5000 | Flask, .NET | ptrm fix 5000 |
| 5173 | Vite | ptrm fix 5173 |
| 8000 | Django, PHP | ptrm fix 8000 |
| 8080 | Java, Spring, Alt HTTP | ptrm fix 8080 |
| 5432 | PostgreSQL | ptrm fix 5432 (warns!) |
| 6379 | Redis | ptrm fix 6379 (warns!) |
| 27017 | MongoDB | ptrm fix 27017 (warns!) |
Why Safe Kill Matters
Blindly running kill -9 is dangerous. It sends SIGKILL which:
- Does not allow the process to clean up resources
- Can cause data corruption in databases (PostgreSQL, MongoDB, Redis)
- May leave socket files and lock files behind
- Can orphan child processes
portrm solves this with a 3-tier safety system:
- BLOCKED: System processes (kernel, init, systemd) cannot be killed
- WARNING: Databases and data stores show a warning with data loss risk
- SAFE: Dev servers and build tools are approved for safe termination
Kill port processes the safe way
portrm identifies services, checks safety, and does graceful shutdown. One command.