Your cross-platform port detective β find, inspect, and kill processes by port number or process name.
No dependencies. Works on macOS, Linux, and Windows.
Every fullstack developer has googled lsof -i :3000 at least once a week. portcop makes it one clean command that works everywhere β no memorizing OS-specific flags, no piping through grep, no copy-pasting PIDs.
npm install -g portcopportcop 3000 Checking port 3000...
β Port 3000 is occupied
Process : node
PID : 8421
Command : node server.js
Kill it? (y/n)
portcop 3000 --kill β Killed node (PID 8421)
portcop 3000 4000 5000 β Port 3000 β node PID 8421 node server.js
β Port 4000 is free
β Port 5000 β python PID 9103 python app.py
Kill all 2 occupied? (y/n)
portcop ls Scanning all occupied ports...
3000 node PID 8421 node server.js
5173 node PID 9103 node vite.js
8080 python PID 9210 python manage.py runserver
3 ports occupied
portcop -n node Searching for processes matching "node"...
Found 3 processes matching "node"
β Port 3000 node PID 8421
node server.js
β Port 5173 node PID 9103
node vite.js
β Port 8080 node PID 9210
node webpack.js
Kill all 3? y / n / ports (e.g. 3000,5173,8080)
At the prompt you can:
yβ kill all matching processesnβ cancel, no action taken3000β kill a single port only3000,5173β kill specific ports, leave the rest running
portcop -n node --kill β Killed node (PID 8421)
β Killed node (PID 9103)
β Killed node (PID 9210)
portcop free 3000 β Port 3000 is free
portcop free 3000-3010 Scanning ports 3000β3010...
β First free port: 3003
portcop free 3000+ --count 5 Finding 5 free ports from 3000...
β 3000
β 3001
β 3003
β 3005
β 3006
macOS: uses lsof
Linux: tries 3 strategies in order, using the first one that works:
lsofβ available on most distrosssβ modern replacement for netstat, used when lsof isn't installed/proc/net/tcpβ pure Linux kernel file, no tools needed at all. Works in Docker containers, CI runners, and minimal environments where nothing is installed
Windows: chains netstat -ano β tasklist (no single command gives port + process name together)
| OS | Kill |
|---|---|
| macOS / Linux | kill -9 PID |
| Windows | taskkill /PID /F |
All OS differences are abstracted away. The CLI output is identical everywhere.
Note: On some systems, killing processes on privileged ports (< 1024) may require
sudo.
| Flag | Alias | Description |
|---|---|---|
--kill |
-k |
Kill without confirmation prompt |
--name |
-n |
Search by process name |
--count N |
Number of free ports to find | |
--help |
-h |
Show help |
| Command | Description |
|---|---|
portcop <port> |
Check who is using a port |
portcop <port> --kill |
Kill the process without asking |
portcop <p1> <p2> <p3> |
Check multiple ports at once |
portcop ls |
List all occupied ports |
portcop -n <name> |
Find all ports used by a process name |
portcop -n <name> --kill |
Kill all processes matching a name |
portcop free <port> |
Check if a port is free |
portcop free <start>-<end> |
Find first free port in range |
portcop free <port>+ --count N |
Find next N free ports starting from port |
node test.jsThe test suite spins up real TCP servers to verify behavior end-to-end, with zero test framework dependencies.
MIT