Coffee
← Blog Mac Productivity

lsof Port on Mac: -i :PORT, -nP, LISTEN and -t Explained

By FavTray · · Updated

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: 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:

FlagWhat it doesWhy you want it
-iTCP:8080Select TCP sockets on port 8080Narrows hundreds of open sockets 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 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:

CommandMatchesTypical use
lsof -i :8080TCP and UDP, any state, on 8080Quick look, with names resolved (slower)
lsof -nP -i :8080Same, raw numbersQuick look, faster
lsof -nP -i tcp:8080TCP only, any stateServers plus open connections
lsof -nP -iTCP:8080 -sTCP:LISTENTCP, listening onlyWho owns the port (the one to use)
lsof -nP -i4TCP:8080 -sTCP:LISTENSame, IPv4 onlyWhen IPv4 and IPv6 rows confuse you
lsof -nP -i @127.0.0.1Sockets on the IPv4 loopback addressLocal-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)
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, 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:

  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 about 30 seconds on macOS (twice the net.inet.tcp.msl value of 15,000 ms) 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.

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.

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
Listening ports of one command namelsof -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.docke in Docker
6379Redisredis-ser
8080Spring Boot, Tomcat, generic HTTPjava
27017MongoDBmongod

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.

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 tcpYes, a process:pid column on macOS 27When 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?

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.

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.

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.