CH-J Toolsserver management over SSH
Menu
All guides and articles →

How to find out which process is using a specific port

Find the owner of a TCP or UDP socket, distinguish a listener from a client connection, and assign a process to a service. Including IPv6, systemd, and containers.

A port needs a protocol, address, and network context.

The number 443 itself does not specify a unique object. TCP 443 and UDP 443 are different sockets and can be used by different processes on the same machine. The same number can be bound to different addresses or in separate network namespaces. Therefore, when searching, type the protocol, the local address, and whether you want a listening service or an already established connection.

A typical goal is to find a program that is preventing a service from starting by reporting Address already in use. Another question is which process is communicating with a foreign server on port 443. In the first case, you are looking for a local listen or bind, in the second, a remote target port. Confusing the two cases leads to the erroneous identification of a regular client as a web server.

The following examples are for reading and correspond to Linux with iproute2. They do not require killing the process or changing the firewall. If you want to intervene in the service you find, do so only after determining its owner, meaning and management. A socket on an important port may belong to a completely legitimate shared infrastructure.

You can find the TCP listener via ss

The -l switch selects listening, -t TCP, -n leaves numeric addresses and ports, and -p adds processes if you have access to them. The explicit filter is more precise than searching for a number via generic grep: the string 443 could also appear in the remote port or in another field. Administrative privileges are often required to fully view foreign processes.

sudo ss -lntp 'sport = :443'
# Všechny TCP listenery:
sudo ss -lntp
# Samostatně IPv4 a IPv6:
sudo ss -4 -lntp 'sport = :443'
sudo ss -6 -lntp 'sport = :443'

In the output, watch for Local Address:Port, status, and users with the process name and PID. The address 127.0.0.1 means IPv4 loopback, not reachable from the internet. The address 0.0.0.0 usually means all local IPv4 addresses. IPv6 [::] must be evaluated against the socket settings; do not automatically assume that it demonstrates both address families at the same time.

An empty listing says that no matching listener was found at the given time and context. It is not a complete statement about the remote availability of the server name. DNS may point to a different machine, port may be translated, and the process may be running in a different namespace. In addition, for a short-lived service, it may die between two checks.

UDP and client connections require a different perspective

UDP does not have the same connection lifecycle as TCP. For UDP service, use the appropriate filter and check the local endpoint. For example, HTTP/3 uses QUIC over UDP, so a working TCP 443 for HTTPS does not itself prove a listener or a UDP 443 pass. This means that two independent paths can meet on one number.

sudo ss -lunp 'sport = :443'
# Aktivní TCP komunikace s místním nebo vzdáleným portem 443:
sudo ss -tnp '( sport = :443 or dport = :443 )'

In the second command, you no longer limit the listing to listening. Distinguish between local and remote sides and states like ESTAB or TIME-WAIT. TIME-WAIT after a terminated TCP connection is not automatically an active web process that needs to be killed. Some system states do not even have a process owner in the same way as an open application descriptor.

A local client can communicate to remote port 443 from a randomly assigned source port. If you are addressing its communication, a filter on only local port 443 would miss it. Conversely, listing all remote ports 443 may contain updates, API or diagnostic requests and says nothing about who is serving your public HTTPS.

Lsof will complete the look through open files and sockets

If lsof is available on the system, you can use it to verify the same problem in another way. Select a specific log and status. It is not necessary to install another package for each initial check if ss provided enough information. The second tool is especially useful for assigning descriptors to a specific process.

sudo lsof -nP -iTCP:443 -sTCP:LISTEN
sudo lsof -nP -iUDP:443

The -nP options prevent the translation of addresses and ports to names, making it easier to match the exact endpoint and not be held up by DNS queries. Keep track of the PID, FD, and address. Multiple lines can be a single process with multiple sockets, or multiple processes sharing a listener. Therefore, counting lines is not a reliable count of independent services.

When combining multiple lsof filters, verify their logic. Some selections are combined as alternatives by default; the -a switch has its own meaning for their intersection. It is not a good idea to build a long filter by trial and error and assume that each additional switch automatically narrows the result. For a common question, stick to a simple, unambiguous query.

From PID, go to service and owner

The PID found is a start, not a termination decision. Find out the account, parents, and executable. For systemd, the status with PID may show the corresponding unit. If the process has terminated in the meantime, check the new status: PID numbers are reused and the old listing is not a safe basis for a later signal.

ps -p PID -o pid,ppid,user,comm,lstart
sudo readlink -f /proc/PID/exe
systemctl status PID --no-pager

Replace PID with an actual number. For a shared web server, a socket can belong to both the main process and workers. This is not just a conflict between multiple different installations. Review the process tree and service management configuration. For a container, the PID and visible paths can differ between the host and the internal environment.

Full command arguments may contain non-public values. Read them only when you need them, and verify them before sharing. Also, the process name can be set so that it is not itself a trusted identifier for the binary. For common diagnostics, use multiple related references instead of a single well-known name.

Systemd can hold a port before the service starts

When a socket is activated, the systemd listener opens and passes it to the service only when needed. This is a common reason why a stopped or not yet started daemon does not mean a free port. On some Ubuntu installations this applies to SSH, for example. Therefore, if there is a conflict, check the socket units as well, not just the service.

systemctl list-sockets --all --no-pager
# U nalezené jednotky:
systemctl cat NAZEV.socket
systemctl show NAZEV.socket -p Listen

Stopping the daemon itself may not release the socket, which is still managed by another unit. It is not advisable to handle this condition by forcibly terminating the systemd process or accidentally deleting unit files. Edit the correct configuration source, prepare a rollback, and respect service dependencies. After the change, verify the real listener and the new connection.

For Unix sockets, use ss -xlnp instead of the network port. For example, PHP-FPM may listen on the path in /run and not use TCP port 9000 at all. Searching by network port alone would then lead to the erroneous conclusion that it is not running. Distinguish the endpoint type according to the actual configuration of the application.

Containers, NAT, and public ingress port

In a container infrastructure, a public port may be mapped to another internal port. A NAT rule may provide the forwarding without a regular separate listener in the host process. Depending on the configuration, a proxy process may also be used. Therefore, an empty ss on the host may not explain the behavior of the entire published port.

# Pokud je na systému používán Docker:
docker ps --format "table {{.Names}}	{{.Ports}}"
# Cílené zobrazení publikovaných portů konkrétního kontejneru:
docker port JMENO_KONTEJNERU

Check for the correct container, network, and actual mapping. In Kubernetes, the traffic can be handled by another layer of service and network plugin. Don't derive the application owner from just one host socket. On the other hand, no container tool is needed if the server doesn't use containers at all; adapt the diagnostics to the actual architecture.

Similarly, for a reverse proxy, distinguish between the input process and the backend. NGINX on port 443 can forward the request to an application on 127.0.0.1:8080 or a Unix socket. An open public port does not tell you which backend is handling a particular domain or URL. You also need an effective routing configuration for this question.

What to do in case of conflict and how to verify the result

For Address already in use, first confirm the protocol, address, and namespace of the newly started service. Then decide which service should own the endpoint. Solutions may include a different bind, fixing the duplicate start, or a controlled termination of the old instance. Do not select a process to terminate based solely on its higher PID or older start time.

  • The exact local address, protocol, and port are specified.
  • The socket owner corresponds to the expected service or socket entity.
  • Any container or reverse proxy mapping is taken into account.
  • The change maintains administrative access and has a rollback procedure.
  • After the repair, the new requested session works, not just the already established connection.

In CH-J Tools, you can perform the same read checks in the terminal and compare them with the service status. Formulate the output precisely: for example, "TCP 443 on IPv4 loopback is held by this unit" instead of the general "port is busy". A precise diagnosis prevents unnecessary restarts of the entire application and interference with unrelated firewalls.

Frequently asked questions

Is grep 443 in netstat output enough?

For orientation sometimes yes, but it can confuse the local and remote side. The exact ss filter by protocol and sport or dport is more unambiguous.

Why don't I see the socket PID?

You may be missing permissions, the process has already ended, or you are in a different namespace. Some TCP states also do not have a regular open application descriptor.

Does open TCP 443 mean working HTTP/3?

No. HTTP/3 uses QUIC over UDP and needs its own path and actual successful transmission.

Can I terminate the found process right away?

First, determine its role, service, and impact. The port may be held by a shared service, container, or systemd socket activation.

Detailed documentation

iproute2: ss and socket filters →

lsof: network selections and process owners →

systemd: socket units →

Docker: published container ports →

Biometric unlock and security →

All tutorials by category →