“Address already in use” identifies the conflicting port. Ask the kernel which socket is listening, which address it bound, and, when permissions allow, which process owns it.
The commands below were tested on Ubuntu 24.04.4 LTS with Linux 6.8 and
iproute2’s ss. They inspect live network state; they do not stop a service.
Start with the exact TCP port
ss -ltn 'sport = :8080'The flags mean listening, TCP, and numeric output. The filter keeps unrelated
sockets out of the incident record. ss omits listening sockets by default, so
-l matters 1.
Read the local address as carefully as the port:
| Local address | What it normally means |
|---|---|
127.0.0.1:8080 |
IPv4 loopback only |
[::1]:8080 |
IPv6 loopback only |
0.0.0.0:8080 |
all local IPv4 addresses |
[::]:8080 |
all local IPv6 addresses, subject to socket settings |
A listener on loopback is not exposed on an external interface merely because the port number matches. A socket is the kernel endpoint that carries the local address, protocol, state, and options 2.
Add process ownership
ss -ltnp 'sport = :8080'Typical ownership output looks like this:
users:(("python3",pid=1505695,fd=3))Those fields identify the process name, PID, and descriptor that refers to the
socket. A blank Process column does not mean the socket is stale; your user may
not be allowed to see another user’s process details.
Caution:
sudo ss -ltnp 'sport = :8080'is read-only but grants the command a privileged system-wide view. Use it only on a host you administer, and preserve the unprivileged result first.
Confirm identity before acting on the PID:
ps -p 1505695 -o pid=,ppid=,user=,lstart=,args=
readlink /proc/1505695/fd/3Replace both numbers with the current result. /proc/PID/fd exposes one link
per open descriptor; socket links use a socket:[inode] form
3. PIDs are reusable, so an old screenshot is not authorization to
signal today’s process.
Use the matching UDP view
UDP does not have TCP’s LISTEN state, but bound UDP sockets are still visible:
ss -lunp 'sport = :5353'Do not use the TCP command to conclude that a UDP port is free. Also check the
network namespace when a container or service sandbox is involved: ss shows
the namespace in which it runs, not every namespace on the host.
The verified loopback lab
This lab starts one disposable server, waits for its socket, inspects it, then signals only the PID it created:
python3 -m http.server 18765 --bind 127.0.0.1 >/dev/null 2>&1 &
server_pid=$!
attempt=0
while ! ss -H -ltn 'sport = :18765' | grep -q .; do
attempt=$((attempt + 1))
if [ "$attempt" -ge 50 ] || ! kill -0 "$server_pid" 2>/dev/null; then
printf '%s\n' 'server did not become ready' >&2
kill -TERM "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
exit 1
fi
sleep 0.1
done
ss -ltnp 'sport = :18765'
kill -TERM "$server_pid"
wait "$server_pid" 2>/dev/null || trueThe Ubuntu lab reported:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 5 127.0.0.1:18765 0.0.0.0:* users:(("python3",pid=1505695,fd=3))The PID will differ. Record the protocol and port, binding address, current process identity, and descriptor together.
Decide at the service boundary
After identifying the listener, find its owner rather than immediately running
kill:
systemctl status 1505695 --no-pager
cat /proc/1505695/cgroupThe PID-aware systemctl form may map the process to a unit on systemd hosts.
For a container, inspect the runtime’s port publication and namespace. For a
development process, return to the terminal or supervisor that launched it.
After confirming the live PID, manage it through the service, container runtime, terminal, or supervisor that started it.