In this article
Replace 3000 with the port you are investigating. The extra state filter matters: a list of processes associated with a port is not automatically a list of processes listening on that port.
Match the command to the question
Open Terminal and choose the narrowest read-only query that answers your question.
| Question | Command for example port 3000 |
|---|---|
| Which visible sockets involve this TCP port? | lsof -nP -iTCP:3000 |
| Which visible TCP sockets are listening on it? | lsof -nP -iTCP:3000 -sTCP:LISTEN |
| Which matching TCP sockets are established? | lsof -nP -iTCP:3000 -sTCP:ESTABLISHED |
The -nP options keep addresses and ports numeric. They make it easier to compare the number you requested with the actual endpoint fields.
Do not append a command that kills every returned PID just because the output looks unexpected. First decide whether you are investigating a listener, an established client connection or a particular process. Those questions produce different selections.
The upstream lsof manual documents network selection, state filters and the output fields. You can also run man lsof to read the manual shipped with your Mac. Its installed version is the relevant reference for the command you actually run.
Read both ends of an established row
A connected socket’s NAME field can look like this:
127.0.0.1:59421->127.0.0.1:59420 (ESTABLISHED)
The left endpoint belongs to the socket represented by that row; the right endpoint is its peer. Each endpoint contains an address and a port. Here, filtering for 59420 can select the row even though the local port on the left is 59421.
The arrow separates the endpoints. It is not a live indicator that data is currently flowing only from left to right. TCP’s specification, RFC 9293, describes bidirectional data flow and identifies a connection by its pair of sockets.
On a loopback connection, both endpoints are on the same Mac. “Remote” means the other endpoint in that row, not necessarily another physical computer or an internet destination.
If you first need to identify the process associated with an app, use the broader Mac app network-connections guide. This article addresses the next, narrower question: why a port filter includes a row you did not expect.
A controlled comparison: five rows became one
We tested these filters on macOS 15.7.5 on November 3, 2026. One disposable Python process created a TCP listener at 127.0.0.1:59420, then opened two client connections to it. The clients received local ports 59421 and 59422.
All sockets belonged to our test process. Every command included -a -p with that process’s actual PID, so the saved results did not collect unrelated application traffic. The test used loopback only and changed no firewall settings.
| Selection within the test PID | Rows | What appeared |
|---|---|---|
| TCP port 59420 | 5 | One listener, two client sockets, two accepted server sockets |
Port 59420 plus LISTEN | 1 | The listener only |
Port 59420 plus ESTABLISHED | 4 | Both ends of the two connections |
| TCP port 59421 | 2 | Both ends of the first connection |
The first client row was:
127.0.0.1:59421->127.0.0.1:59420 (ESTABLISHED)
Its corresponding accepted server socket appeared as:
127.0.0.1:59420->127.0.0.1:59421 (ESTABLISHED)
Filtering for 59420 selected both rows. Filtering for 59421 also selected both rows. This directly demonstrates why a port match cannot, on its own, tell you that the matching number is the local listening port.
The four established rows represented two connections, not four separate internet transfers. The listener remained a separate socket. Adding LISTEN reduced the result to the one socket that answered the listener question.
These are the actual ports and counts from our fixture. They are not fixed macOS defaults or a prediction of your app’s output. We closed all test sockets afterward.
Narrow a result to one process
If you already know the current PID, combine it with the network selection:
lsof -nP -a -p 12345 -iTCP:3000
Replace both example numbers. The -a combines the PID and network selections with AND. Without the intended combination, a command can select more than the intersection you meant to inspect.
For a listener-only check on that process, add -sTCP:LISTEN. Keep the process identity, endpoint and state together in your notes. A PID can change when an app restarts, so an old PID is not a durable identifier for the application.
A listener’s address adds another distinction. A socket bound to loopback and one bound to all IPv4 interfaces have different scopes. The 0.0.0.0 listener guide explains that address; a port filter does not replace the address check.
What the result cannot settle
An empty result means no matching sockets were visible to that invocation at that time. It does not establish that the app never used the port. A short connection may have ended, another helper may own it, or your account may lack visibility into another process.
These recipes explicitly select TCP. UDP has different behavior and is excluded by -iTCP; do not call an empty TCP result an all-protocol check. LISTEN is a TCP state, not a universal label for every network service.
A visible listener also does not prove that a machine across the internet can reach it. Reachability depends on the address, network path and access controls. Likewise, an established row is not evidence that useful data is moving at that instant.
Finally, a familiar service port is not an application identity or a security verdict. Our port 443 and encryption guide explains why the number alone does not prove TLS.
For a useful troubleshooting record, save the exact command, time, PID, protocol, both endpoints and state. Then state the conclusion at the same scope: “This process had a visible TCP listener on this address and port,” or “This socket matched because its peer used that port.” That distinction prevents a client connection from being mistaken for a local server.


