← Blog Mac Productivity

lsof Port on Mac: Find What's Using Any Port

By FavTray ·

Written by the team behind FavTray, a Mac developer dashboard for the menu bar. We check every app we cover against its own site, docs or a hands-on test, and each post says which.

Short answer: To see what’s using a port on a Mac, run lsof -nP -iTCP:8080 -sTCP:LISTEN in Terminal (swap 8080 for your port). It prints the command, PID and user of the process listening there. No output? Run it again with sudo, because lsof only shows your own processes by default. It’s read-only and safe to run.

TL;DR

  • One port: lsof -nP -iTCP:PORT -sTCP:LISTEN
  • Every listening port: lsof -nP -iTCP -sTCP:LISTEN
  • Just the PID: add -t.
  • Empty but the port is busy: add sudo.
  • Then stop it: kill PID (full kill port mac guide).

Every command on this page only reads. The single destructive step, kill, is called out where it appears.

What is the lsof command to check a port on Mac?

lsof means “list open files” (full reference: the lsof manual page, or man lsof). macOS treats network sockets as files, so the same tool that finds who has a document open also finds who owns a port. It ships with macOS, nothing to install.

# read-only
lsof -nP -iTCP:8080 -sTCP:LISTEN

Each part has a job:

FlagWhat it doesWhy you want it
-iTCP:8080Select TCP sockets on port 8080Narrows thousands of open files to one port
-sTCP:LISTENKeep only sockets in the LISTEN stateShows the server, hides clients like your browser
-nDon’t resolve IPs to hostnamesFaster, and shows the real bind address
-PDon’t turn port numbers into namesShows 8080, not http-alt
-tPrint PIDs onlyFor piping into kill

The most-copied version online is lsof -i :8080 (Flask’s server docs use lsof -P -i :5000). It works, but it matches every socket on that port, including your browser’s connection to the server. Pipe that into kill and you close the browser too. Keep -sTCP:LISTEN.

How do I read lsof output?

COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    48213 akash   20u  IPv6 0x8c1f2a6b3e7d1a90      0t0  TCP *:3000 (LISTEN)
ColumnMeaningWhat to do with it
COMMANDProcess name, cut to 9 charactersControlCe is ControlCenter. Add +c 0 for the full name
PIDProcess IDThe number you pass to ps or kill
USEROwner of the processNot you? You need sudo to stop it
FDFile descriptor number plus mode (u = read and write)Rarely matters for ports
TYPEIPv4 or IPv6A server can listen on both, so two rows is normal
DEVICE, SIZE/OFFKernel address and offsetIgnore for ports
NODEProtocol, TCP or UDP
NAMEAddress, port and stateThe important column, see below

The NAME column tells you who can reach the server:

NAME showsListening onReachable from
*:3000 (LISTEN)Every interfaceThis Mac and other devices on your network
127.0.0.1:3000 (LISTEN)IPv4 loopbackThis Mac only
[::1]:5173 (LISTEN)IPv6 loopbackThis Mac only
127.0.0.1:52144->127.0.0.1:3000 (ESTABLISHED)A connection, not a listenerIt’s a client, often your browser

That table is also the fastest way to debug “it works on my Mac but not on my phone”: a loopback address means the server never accepted outside connections. The fix is in access localhost from your phone.

What should I do once I have the PID?

Find out what the process is before you stop it. Both of these are read-only:

# full command line, parent PID and running time
ps -o pid,ppid,etime,command -p 48213

# the folder it was started from, which tells you the project
lsof -a -p 48213 -d cwd

Then stop it. This step is destructive: the process ends and anything unsaved in it is lost.

kill 48213        # polite: SIGTERM
kill -9 48213     # only if it's still there after a few seconds

If the owner is Docker (com.docker.backend), a Homebrew service, or macOS itself (ControlCe on 5000 or 7000), stop it through its own tool instead. The address already in use guide has a table for each, and port 5000 has its own fix.

Why does lsof show nothing?

  1. It’s not your process. Without sudo, lsof skips processes owned by root and other users. Try sudo lsof -nP -iTCP:8080 -sTCP:LISTEN.
  2. Wrong protocol. UDP sockets have no LISTEN state, so -sTCP:LISTEN hides them. Use lsof -nP -iUDP:5353.
  3. TIME_WAIT. A connection that just closed holds the port for 30 seconds on macOS with no owning process. Only netstat sees it (below).
  4. Missing -a in a combined query. lsof ORs its selectors by default, so lsof -p 48213 -i means “files of PID 48213, or any network file”. Add -a to AND them: lsof -a -p 48213 -i.

The lsof port cheat sheet

Every command here is read-only. Add sudo to any of them to see other users’ processes.

TaskCommand
Who listens on a portlsof -nP -iTCP:3000 -sTCP:LISTEN
Every listening TCP portlsof -nP -iTCP -sTCP:LISTEN
A range of portslsof -nP -iTCP:3000-3010 -sTCP:LISTEN
PID onlylsof -t -iTCP:3000 -sTCP:LISTEN
IPv4 onlylsof -nP -i4TCP:3000 -sTCP:LISTEN
UDP on a portlsof -nP -iUDP:5353
Every port a process has openlsof -nP -a -p 48213 -i
Every port a command name has openlsof -nP -a -c node -iTCP -sTCP:LISTEN
Full command nameslsof +c 0 -nP -iTCP -sTCP:LISTEN
Live connections to a portlsof -nP -iTCP:3000 -sTCP:ESTABLISHED
Refresh every 2 secondslsof -r 2 -nP -iTCP:3000 -sTCP:LISTEN
A process’s working folderlsof -a -p 48213 -d cwd

Use these often? Add a shell function to ~/.zshrc, then open a new tab:

port() { lsof -nP -iTCP:"$1" -sTCP:LISTEN; }

Now port 3000 does the lookup.

Which process usually owns which port on a Mac?

When you run lsof -nP -iTCP -sTCP:LISTEN for the first time, the list is longer than you expect. These are the ports developers see most, and what normally sits on them:

PortUsuallyCOMMAND in lsof
3000Node, Next.js, Express, Railsnode, ruby
4321Astro dev servernode
5000, 7000macOS AirPlay Receiver, per Apple’s port list (or Flask on 5000)ControlCe (or Python)
5173Vite dev servernode
5432PostgreSQLpostgres or com.docker.backend
6379Redisredis-ser
8080Spring Boot, Tomcat, generic HTTPjava
27017MongoDBmongod

If a database port shows com.docker.backend, the database is running in a container, so stop it with docker stop, not kill. Everything else you don’t recognise is worth a ps -o command= -p PID before you touch it: macOS and apps you’ve installed open listening ports of their own.

What about netstat, ss or Activity Monitor?

ToolShows the process?Good for
lsofYes, name and PIDAlmost everything on this page
netstat -an -p tcpNot by defaultTIME_WAIT connections, which lsof can’t attribute
netstat -anv -p tcpPID in extra columns on recent macOSWhen you want both in one list
ssNot on macOSIt’s a Linux tool
Activity MonitorYes, per processBuilt-in, no Terminal

The macOS netstat is the BSD version, so its flags differ from Linux: -p tcp means “protocol TCP”, not “show processes”. To find TIME_WAIT entries on one port:

# read-only: the dot before the port matters on macOS
netstat -an -p tcp | grep '\.3000 '

Activity Monitor, Apple’s built-in option, can show ports too: double-click a process, then open the Open Files and Ports tab. The catch is direction. It answers “what ports does this process have?”, not “which process has port 3000?”, so you need to guess the process first.

Is there a faster way than typing lsof?

We make FavTray, so weigh our take accordingly. FavTray’s Ports runs lsof for you and keeps the result one click away in the menu bar: every listening TCP port, grouped by type (dev servers, Python, Java, Docker, databases, web servers, system), with search by port number or process name and an auto-refresh you can set. Kill asks for confirmation first.

Scanning and search are free with no limit, Free includes 10 kills a day, and Pro is $4.99 once for unlimited. If you only check a port once a week, the port function above is enough, and our roundup of menu bar apps for developers covers other tools in this space. If you run several projects and ports every day, a list that’s always current saves the typing. For the one-line kill commands, see the kill port 3000 mac guide.

Try FavTray Free

One free Mac menu bar app: notch island, ports, keep-awake, clipboard, eye rest, and Claude and Codex limits.

Download Free

Frequently Asked Questions

What is the lsof command to check a port on Mac?

Run 'lsof -nP -iTCP:8080 -sTCP:LISTEN', replacing 8080 with your port. -iTCP:8080 selects TCP sockets on that port, -sTCP:LISTEN keeps only the server that is listening, and -nP prints raw IP addresses and port numbers instead of looking up names, which makes it faster. The output names the command, its PID and the user who owns it.

How do I list all listening ports on a Mac?

Run 'lsof -nP -iTCP -sTCP:LISTEN'. It lists every TCP socket in the listening state that belongs to your user, with the process name and PID. Add sudo in front to include processes owned by root and other users. For UDP, which has no listening state, use 'lsof -nP -iUDP' instead.

Why does lsof show nothing for a port that is in use?

Usually because the process belongs to root or another user, and lsof only shows your own processes without sudo. Run 'sudo lsof -nP -iTCP:PORT -sTCP:LISTEN'. If that's empty too, the port may be held by a closed connection in TIME_WAIT, which has no owning process and clears within 30 seconds on macOS. netstat can show those.

What does -nP mean in lsof?

-n stops lsof from turning IP addresses into hostnames, and -P stops it from turning port numbers into service names such as 'http-alt' for 8080. Both lookups are slow and make the output harder to scan, so -nP gives you raw numbers like 127.0.0.1:8080, faster. It's worth adding to every lsof port command.

Does netstat show the process ID on Mac?

Not by default. On macOS, 'netstat -p' means protocol, not process, unlike Linux. 'netstat -anv -p tcp' adds extra columns that include the owning process ID on recent macOS versions, but lsof is easier because it prints the command name and PID in plain columns. There's no 'ss' command on macOS.

Something new: My Dock Buddies