Find Which Process Is Using a Port with lsof

Identify the process holding a TCP port — the classic fix for 'address already in use' errors.

macOSProcessesportlsofDiagnosticsLow risk
Run lsof -nP -iTCP:8080 -sTCP:LISTEN to list the process (with PID and name) listening on port 8080; change 8080 to any port.

01Command

Command
$ lsof -nP -iTCP:8080 -sTCP:LISTEN

02What it does

lsof maps open files to processes, and on macOS sockets are files — so -iTCP:8080 selects every connection on that port and -sTCP:LISTEN narrows it to servers actually accepting connections. -n skips DNS lookups and -P prints raw port numbers, making the output instant. The PID it prints is what you pass to kill to free the port.

03Risk

RiskLow risk
!Warning: Finding a listener is read-only, but killing it isn't — check the process name first; a port held by a system service (like mDNSResponder on 5353) should not be killed.

04Undo

Undo
$ kill <PID from output>

05Sources

  • lsof(8) man page
    manpagez.com · technical · 2026-09-17
    Evidence: The lsof man page documents the -iTCP address specification and the -sTCP:LISTEN state filter that selects only processes listening on the port.
  • lsof - List Open Files
    SS64 · technical · 2026-09-17
    Evidence: Documents the -i option in the form [46][protocol][@host][:port] to list network connections by TCP port and protocol, plus -n (no name resolution) and -P (numeric ports).

Last verified: 2026-09-19 · Category: Network

06Related solutions