lsof Port on Mac: -i :PORT, -nP, LISTEN and -t Explained
Short answer: The lsof port command on a Mac is lsof -nP -iTCP:PORT -sTCP:LISTEN, for example lsof -nP -iTCP:3000 -sTCP:LISTEN. It prints the command name, PID and user of the process listening on that port. Add -t to print only the PID, and sudo if the output is empty. It’s built into macOS and read-only.
TL;DR
- One port:
lsof -nP -iTCP:PORT -sTCP:LISTEN - Quick and loose:
lsof -i :PORT(also matches clients and UDP). - 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(kill port 3000 mac guide).
Every command on this page only reads, and each was run on macOS 27 (lsof revision 4.91, the version Apple ships) in November 2026. The single destructive step, kill, is called out where it appears.
What is the lsof command to check a port on Mac?
The command is lsof -nP -iTCP:8080 -sTCP:LISTEN, with 8080 swapped for your port. lsof means “list open files” (full reference: the lsof manual page, or man lsof in Terminal). macOS treats network sockets as files, so the same tool that finds who has a document open also finds who owns a port. It lives at /usr/sbin/lsof, so there is 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 hundreds of open sockets 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 ps, scripts, or piping into kill |
What does lsof -i :PORT do?
lsof -i :PORT lists every open network socket on that port number, TCP and UDP, whatever its state. It’s the most-copied form online: Flask’s development server docs use lsof -P -i :5000 for macOS. It works, but it is looser than most people expect.
# read-only: all sockets on 8080, servers and clients
lsof -i :8080
The -i selector takes the form [46][protocol][@host][:port], so you can tighten it step by step:
| Command | Matches | Typical use |
|---|---|---|
lsof -i :8080 | TCP and UDP, any state, on 8080 | Quick look, with names resolved (slower) |
lsof -nP -i :8080 | Same, raw numbers | Quick look, faster |
lsof -nP -i tcp:8080 | TCP only, any state | Servers plus open connections |
lsof -nP -iTCP:8080 -sTCP:LISTEN | TCP, listening only | Who owns the port (the one to use) |
lsof -nP -i4TCP:8080 -sTCP:LISTEN | Same, IPv4 only | When IPv4 and IPv6 rows confuse you |
lsof -nP -i @127.0.0.1 | Sockets on the IPv4 loopback address | Local-only servers and their clients |
The catch with plain lsof -i :8080: if your browser has the page open, its connection to the server matches too. Pipe that into kill and you close the browser along with the server. Keep -sTCP:LISTEN whenever the next step is a kill.
How do I list all network ports with lsof?
Run lsof -nP -i to list every open network socket on your Mac, or lsof -nP -iTCP -sTCP:LISTEN to list only the ports that something is serving on. The first is long (several hundred lines on a normal working Mac, mostly browser and app connections). The second is the short list that answers “what’s running on my Mac?”
# read-only: every listening TCP port you own
lsof -nP -iTCP -sTCP:LISTEN
# read-only: same, including root and other users
sudo lsof -nP -iTCP -sTCP:LISTEN
Expect a few entries you didn’t start. On a fresh look you’ll often see rapportd (Apple’s device-to-device service), ControlCe (Control Center, which runs the AirPlay Receiver on 5000 and 7000), and helpers from apps you’ve installed.
How do I read lsof output?
Read three columns: COMMAND is the program, PID is the number you pass to ps or kill, and NAME shows the address, port and state (LISTEN means it’s the server).
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, then stop it with kill PID only if you’re sure. 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.docke, short for 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.
How do I get just the PID with lsof -t?
Add -t and lsof prints only process IDs, one per line, with no header. That’s what you want in scripts and one-liners.
# read-only
lsof -t -iTCP:3000 -sTCP:LISTEN
# 48213
# read-only: show what that PID is
ps -o pid,etime,command -p "$(lsof -t -iTCP:3000 -sTCP:LISTEN | paste -sd, -)"
The famous one-liner kill $(lsof -t -i :3000) is destructive and too broad: without -sTCP:LISTEN it can also hit clients connected to the port. If you want the one-liner, use the narrow form, and read how to kill a process on a port first:
# destructive: stops whatever is listening on 3000
kill $(lsof -t -iTCP:3000 -sTCP:LISTEN)
If more than one process listens (an IPv4 and an IPv6 listener, or a parent and its workers), -t prints several PIDs and kill receives all of them.
Why does lsof show nothing?
An empty result almost always means the process isn’t yours (fix: sudo), the socket is UDP, or the port is held by a closed connection. Work through these in order:
- 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 about 30 seconds on macOS (twice the
net.inet.tcp.mslvalue of 15,000 ms) with no owning process. Onlynetstatsees 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.
What are the most useful lsof port commands?
The twelve commands below cover nearly every lsof port lookup on a Mac. 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 |
| Listening ports of one command name | 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.docke in Docker |
| 6379 | Redis | redis-ser |
| 8080 | Spring Boot, Tomcat, generic HTTP | java |
| 27017 | MongoDB | mongod |
If a database port shows com.docke (com.docker.backend with +c 0), 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?
lsof is the best built-in tool for mapping a port to a process on macOS; netstat sees connections lsof can’t attribute, and Activity Monitor works without Terminal.
| 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 | Yes, a process:pid column on macOS 27 | 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?
Yes: a shell function like port above, or a menu bar app that runs lsof for you. FavTray is a macOS menu bar app that bundles developer and productivity tools, free with daily limits, $4.99 once for Lifetime. 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, with a 7-day full trial and no card. 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 port 3000 one-liners, and if a server refuses to start, the port already in use fix.
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.
What is the difference between lsof -i :8080 and lsof -i tcp:8080?
'lsof -i :8080' matches every TCP and UDP socket on port 8080, listening or connected, so your browser's connection shows up next to the server. 'lsof -i tcp:8080' limits it to TCP. Add '-sTCP:LISTEN' to keep only the process that owns the port, which is the one you usually want to inspect or stop.
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 about 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. Add it to every lsof port command.
How do I get only the PID of the process on a port?
Add -t: 'lsof -t -iTCP:3000 -sTCP:LISTEN' prints just the process ID, one per line, with no header. That makes it easy to pass to other commands, for example 'ps -p $(lsof -t -iTCP:3000 -sTCP:LISTEN | paste -sd, -)' to see what it is. Piping it into kill stops the process, so check what it is first.