lsof Port on Mac: Find What's Using Any Port
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:
| Flag | What it does | Why you want it |
|---|---|---|
-iTCP:8080 | Select TCP sockets on port 8080 | Narrows thousands of open files to one port |
-sTCP:LISTEN | Keep only sockets in the LISTEN state | Shows the server, hides clients like your browser |
-n | Don’t resolve IPs to hostnames | Faster, and shows the real bind address |
-P | Don’t turn port numbers into names | Shows 8080, not http-alt |
-t | Print PIDs only | For 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)
| Column | Meaning | What to do with it |
|---|---|---|
COMMAND | Process name, cut to 9 characters | ControlCe is ControlCenter. Add +c 0 for the full name |
PID | Process ID | The number you pass to ps or kill |
USER | Owner of the process | Not you? You need sudo to stop it |
FD | File descriptor number plus mode (u = read and write) | Rarely matters for ports |
TYPE | IPv4 or IPv6 | A server can listen on both, so two rows is normal |
DEVICE, SIZE/OFF | Kernel address and offset | Ignore for ports |
NODE | Protocol, TCP or UDP | |
NAME | Address, port and state | The important column, see below |
The NAME column tells you who can reach the server:
NAME shows | Listening on | Reachable from |
|---|---|---|
*:3000 (LISTEN) | Every interface | This Mac and other devices on your network |
127.0.0.1:3000 (LISTEN) | IPv4 loopback | This Mac only |
[::1]:5173 (LISTEN) | IPv6 loopback | This Mac only |
127.0.0.1:52144->127.0.0.1:3000 (ESTABLISHED) | A connection, not a listener | It’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?
- It’s not your process. Without
sudo,lsofskips processes owned by root and other users. Trysudo lsof -nP -iTCP:8080 -sTCP:LISTEN. - Wrong protocol. UDP sockets have no LISTEN state, so
-sTCP:LISTENhides them. Uselsof -nP -iUDP:5353. - TIME_WAIT. A connection that just closed holds the port for 30 seconds on macOS with no owning process. Only
netstatsees it (below). - Missing
-ain a combined query.lsofORs its selectors by default, solsof -p 48213 -imeans “files of PID 48213, or any network file”. Add-ato 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.
| Task | Command |
|---|---|
| Who listens on a port | lsof -nP -iTCP:3000 -sTCP:LISTEN |
| Every listening TCP port | lsof -nP -iTCP -sTCP:LISTEN |
| A range of ports | lsof -nP -iTCP:3000-3010 -sTCP:LISTEN |
| PID only | lsof -t -iTCP:3000 -sTCP:LISTEN |
| IPv4 only | lsof -nP -i4TCP:3000 -sTCP:LISTEN |
| UDP on a port | lsof -nP -iUDP:5353 |
| Every port a process has open | lsof -nP -a -p 48213 -i |
| Every port a command name has open | lsof -nP -a -c node -iTCP -sTCP:LISTEN |
| Full command names | lsof +c 0 -nP -iTCP -sTCP:LISTEN |
| Live connections to a port | lsof -nP -iTCP:3000 -sTCP:ESTABLISHED |
| Refresh every 2 seconds | lsof -r 2 -nP -iTCP:3000 -sTCP:LISTEN |
| A process’s working folder | lsof -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:
| Port | Usually | COMMAND in lsof |
|---|---|---|
| 3000 | Node, Next.js, Express, Rails | node, ruby |
| 4321 | Astro dev server | node |
| 5000, 7000 | macOS AirPlay Receiver, per Apple’s port list (or Flask on 5000) | ControlCe (or Python) |
| 5173 | Vite dev server | node |
| 5432 | PostgreSQL | postgres or com.docker.backend |
| 6379 | Redis | redis-ser |
| 8080 | Spring Boot, Tomcat, generic HTTP | java |
| 27017 | MongoDB | mongod |
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?
| Tool | Shows the process? | Good for |
|---|---|---|
lsof | Yes, name and PID | Almost everything on this page |
netstat -an -p tcp | Not by default | TIME_WAIT connections, which lsof can’t attribute |
netstat -anv -p tcp | PID in extra columns on recent macOS | When you want both in one list |
ss | Not on macOS | It’s a Linux tool |
| Activity Monitor | Yes, per process | Built-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.
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.