Skip to content

Hawila/portcop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

portcop πŸš”

Your cross-platform port detective β€” find, inspect, and kill processes by port number or process name.

No dependencies. Works on macOS, Linux, and Windows.


Why

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.


Install

npm install -g portcop

Usage

Check what's on a port

portcop 3000
  Checking port 3000...

  ✘ Port 3000 is occupied

    Process : node
    PID     : 8421
    Command : node server.js

  Kill it? (y/n)

Kill immediately without prompt

portcop 3000 --kill
  βœ” Killed node (PID 8421)

Check multiple ports at once

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)

List all occupied ports

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

Find processes by name

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 processes
  • n β€” cancel, no action taken
  • 3000 β€” kill a single port only
  • 3000,5173 β€” kill specific ports, leave the rest running

Kill all processes by name (no prompt)

portcop -n node --kill
  βœ” Killed node (PID 8421)
  βœ” Killed node (PID 9103)
  βœ” Killed node (PID 9210)

Check if a port is free

portcop free 3000
  βœ” Port 3000 is free

Find first free port in a range

portcop free 3000-3010
  Scanning ports 3000–3010...
  βœ” First free port: 3003

Find next N free ports

portcop free 3000+ --count 5
  Finding 5 free ports from 3000...
  βœ” 3000
  βœ” 3001
  βœ” 3003
  βœ” 3005
  βœ” 3006

How it works

macOS: uses lsof

Linux: tries 3 strategies in order, using the first one that works:

  1. lsof β€” available on most distros
  2. ss β€” modern replacement for netstat, used when lsof isn't installed
  3. /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.


Options

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

Commands

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

Testing

node test.js

The test suite spins up real TCP servers to verify behavior end-to-end, with zero test framework dependencies.


License

MIT

About

your cross-platform port detective πŸš” β€” find, inspect, and kill processes by port

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors