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.
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:LISTEN02What 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
!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 pageEvidence: 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 FilesEvidence: 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
Find Which Process Has a File or Volume Open with lsof
List every open file descriptor — files, directories, and network sockets — per process.
Rebuild the Spotlight index on Mac
Erase the broken Spotlight database so macOS re-indexes your drive from scratch.
Find your Mac's serial number from the Terminal
Read the serial number, model identifier and chip without opening About This Mac.