Back to commands

Apple Terminal

Stops processes

Stop the Process Blocking a Dev Port

A stale local server keeps listening on a port after its terminal window was closed.

Command

lsof -ti tcp:3000 | xargs kill

Before you run this

System impact: Stops matching processes. Can interrupt apps, databases, sync tools, or system services if the PID list is wrong.

When not to use it: Do not use on ports for databases, sync tools, system services, or any process you do not recognize.

Expected output

Usually no output. Inspect the port first; after the command, a repeat port check should show no listener.

System impact

Stops processes. The process IDs returned by lsof are asked to stop with a normal TERM signal.

When to use it

Use only when you are confident the process on that port is your stale local dev server.

When not to use it

Do not use on ports for databases, sync tools, system services, or any process you do not recognize.

Recovery / rollback

Restart the stopped application or dev server if you killed the wrong process.

Example run

Reproduce this demo

These commands prepare a temporary example before running the command under review.

  1. python3 -m http.server 3000 --bind 127.0.0.1 >/tmp/port-3000-listener.log 2>&1 & echo $! > /tmp/port-3000-listener.pid; sleep 1; lsof -nP -iTCP:3000 -sTCP:LISTEN
  2. lsof -nP -iTCP:3000 -sTCP:LISTEN; test "$(lsof -ti tcp:3000)" = "$(cat /tmp/port-3000-listener.pid)" && lsof -ti tcp:3000 | xargs kill; lsof -nP -iTCP:3000 -sTCP:LISTEN || true

next steps

Related commands

Apple Terminal Stops processes

Flush macOS DNS Cache

Changed DNS but your Mac still visits the old place? Flush the resolver cache.

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • LPIC-1 style command-line practice
  • LFCS style performance-task practice
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.