Commandkill

Kill the process using a port

Finds whatever process is bound to a TCP port and force-kills it in one line, using lsof to resolve the port number to a process ID.

Last updated

Commandkill
kill -9 $(lsof -t -i:3000)

How it works

lsof -t -i:3000 lists the process ID(s) bound to port 3000 — -t means "terse" output, PIDs only, with none of lsof's usual columns. Wrapping that in $(...) command substitution feeds the result straight into kill -9, so you never have to look up and retype the PID by hand. -9 sends SIGKILL, an unconditional signal the target process can't intercept or ignore, which guarantees it actually dies even if it's stuck or refusing gentler signals.

This is the standard "something's still holding port 3000 from an old dev server" fix — one line instead of manually running lsof, reading off the PID, then typing a separate kill command.

Watch out for

  • kill -9 gives the process no chance to clean up — no closing file handles, flushing writes, or releasing the port gracefully. Try a plain kill (SIGTERM) first for anything that might have unsaved state, and reach for -9 only if that doesn't work.
  • If multiple processes happen to share the port (rare, but possible with SO_REUSEPORT), lsof -t returns multiple PIDs and this kills all of them at once via the command substitution's word list.
  • This is Linux/macOS only — lsof and this kill syntax don't exist on native Windows. There, find the PID with netstat -ano | findstr :3000, then stop it with taskkill /PID <pid> /F.

Related in Commands