On macOS Big Sur
and later, use this command:
sudo lsof -i -P | grep LISTEN
or to just see just IPv4:
sudo lsof -nP -i4TCP:$PORT | grep LISTEN
On older versions, use one of the following forms:
sudo lsof -nP -iTCP:$PORT | grep LISTEN
sudo lsof -nP -i:$PORT | grep LISTEN
Substitute $PORT
with the port number or a comma-separated list of port numbers.
Prepend sudo
(followed by a space) if you need information on ports below #1024.
The -n
flag is for displaying IP addresses instead of host names. This makes the command execute much faster, because DNS lookups to get the host names can be slow (several seconds or a minute for many hosts).
The -P
flag is for displaying raw port numbers instead of resolved names like http
, ftp
or more esoteric service names like dpserve
, socalia
.
See the comments for more options.
For completeness, because frequently used together:
To kill the PID:
sudo kill -9 <PID>
# kill -9 60401
Best Answer
TCP
is a connection oriented stream over an IP network. It guarantees that all sent packets will reach the destination in the correct order. This imply the use of acknowledgement packets sent back to the sender, and automatic retransmission, causing additional delays and a general less efficient transmission thanUDP
.UDP
is a connection-less protocol. Communication is datagram oriented. The integrity is guaranteed only on the single datagram. Datagrams reach destination and can arrive out of order or don't arrive at all. It is more efficient thanTCP
because it uses non ACK. It's generally used for real time communication, where a little percentage of packet loss rate is preferable to the overhead of aTCP
connection.In certain situations
UDP
is used because it allows broadcast packet transmission. This is sometimes fundamental in cases likeDHCP
protocol, because the client machine hasn't still received anIP
address (this is theDHCP
negotiaton protocol purpose) and there won't be any way to establish aTCP
stream without theIP
address itself.