Last updated: 19 November 2026. Every command and output below was run on Ubuntu 24.04 with iproute2 6.1.0, lsof 4.95 and psmisc 23.7. SeeHow this was checked.
You start a dev server, an Apache restart, or a container, and get Address already in use or EADDRINUSE. Something already owns the port, or the kernel thinks it does. This article shows how to find out what, in the order I would actually do it, and covers the cases where the obvious commands return nothing: another user's process, a connection stuck in TIME-WAIT, a port bound to loopback only.
The quick answer
sudo ss -ltnp 'sport = :8080' That prints the listener on TCP port 8080 and the process that owns it. Here is the real output from a test run with a Python web server on that port:
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 5 0.0.0.0:8080 0.0.0.0:* users:(("python3",pid=150,fd=3)) The process is python3, PID 150. Everything below is variations on that, plus what to do when it comes back empty.
ss: the tool to reach for first
ss ships with iproute2 and has replaced netstat on modern distributions. The flags worth memorizing:
| Flag | Meaning |
|---|---|
-l | listening sockets only |
-t / -u / -x | TCP / UDP / Unix sockets |
-n | numeric ports and addresses (no name lookups) |
-p | show the owning process (needs privileges for other users' processes) |
-a | all states, including established and TIME-WAIT |
sudo ss -ltnp # every TCP listener with its process sudo ss -ltnp 'sport = :8080' # one port sudo ss -lunp 'sport = :5353' # UDP sudo ss -lxp | grep app.sock # Unix domain sockets The UDP check found a nc listener (UNCONN is the UDP equivalent of listening), and the Unix socket check printed u_str LISTEN ... /tmp/ports/app.sock ... users:(("python3",pid=362,fd=3)). For listening sockets, Send-Q is the accept backlog; it showed 5 here, which is Python's default listen(5).
Read the Local Address column carefully. 0.0.0.0:8080 means all IPv4 interfaces. 127.0.0.1:8081 means loopback only. That difference matters for the next section.
lsof and fuser: the alternatives
sudo lsof -nP -iTCP:8080 -sTCP:LISTEN COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME python3 150 root 3u IPv4 2041 0t0 TCP *:8080 (LISTEN) -nP stops lsof from resolving host and port names, and -sTCP:LISTEN filters out established connections so you see the server and not every client. lsof -t prints only the PID, which is handy in scripts. lsof -nU lists Unix sockets.
sudo fuser -v -n tcp 8080 USER PID ACCESS COMMAND 8080/tcp: root 150 F.... python3 Without -v, fuser prints just 8080/tcp: 150. It is the shortest to type, and the only one of the three that can kill the owner directly (fuser -k, covered below). ss is still my default because it also shows TIME-WAIT sockets and states, which the others do not.
When the command shows nothing
1. You are not root
I ran all three as the unprivileged user nobody against a port owned by root:
-
ss -ltnpstill showed the listener on 0.0.0.0:8080, but the Process column was empty. -
lsof -nP -iTCP:8080 -sTCP:LISTENprinted nothing and exited with status 1. -
fuser -v -n tcp 8080also printed nothing and exited with status 1.
An empty result from lsof or fuser as a normal user does not mean the port is free. Re-run with sudo. The same applies on a shared server where the process belongs to another account.
2. Nothing is listening, but the bind still fails: TIME-WAIT
After a server closes a connection, the kernel keeps a record of it for a while so late packets are not mistaken for a new connection. I reproduced this: a server accepted a connection, closed its side first, then exited. Then:
$ ss -tan 'sport = :9000' State Recv-Q Send-Q Local Address:Port Peer Address:Port Process TIME-WAIT 0 0 127.0.0.1:9000 127.0.0.1:37758 $ lsof -nP -i :9000 (no output, exit 1) No process owns it, so lsof and fuser are empty and ss -p has nothing to show. Binding the same port again without SO_REUSEADDR failed with [Errno 98] Address already in use; with SO_REUSEADDR set, the bind succeeded straight away. I timed how long that TIME-WAIT entry lasted: about 60 seconds.
So if ss -tan shows only TIME-WAIT entries on your port, either wait a minute or make the server set SO_REUSEADDR. Most web servers and frameworks already do. This is the usual cause of the error that "fixes itself" if you wait.
3. It is bound to loopback only
A listener on 127.0.0.1:8081 is invisible from other machines. I checked: curl http://127.0.0.1:8081/ returned 200, but the same port on the host's other address (192.0.2.2 here) failed with curl exit code 7, connection refused. The wildcard listener on 0.0.0.0:8080 answered on both. If a service works locally and not from outside, check the Local Address column before touching a firewall. For a real service, a loopback bind behind a reverse proxy is often exactly what you want.
4. It is on IPv6, or in a container
A dual-stack listener on [::] can occupy the IPv4 port as well, and you will see it in ss and in lsof as an IPv6 entry. I could not test this, because the sandbox has no IPv6 support, so I am leaving this as a thing to look for in the Local Address column rather than a verified result. For published container ports, docker ps --filter publish=8080 lists the container that exposes a port. I did not test Docker here either, and in ss output the owner of a published port can be the Docker proxy process, not your app.
Find out what the process is
A PID alone is not much. These three commands tell you what it is and where it was started from:
ps -o pid,user,etime,args -p 150 ls -l /proc/150/cwd tr '\0' ' ' < /proc/150/cmdline PID USER ELAPSED COMMAND 150 root 00:05 python3 -m http.server 8080 /tmp/ports python3 -m http.server 8080 The command line and working directory usually identify the project. If the process is managed by systemd, check systemctl status <pid> before killing it; a service manager may restart it immediately. I did not test systemd behavior in this environment.
Free the port
Prefer stopping the service properly (systemctl stop, docker stop, your process manager). If it is a stray process, in this order:
sudo kill 150 # SIGTERM: lets the process shut down cleanly sleep 1 sudo ss -ltnp 'sport = :8080' # confirm it is gone After kill 150, the listener count on 8080 was zero. I also tested a process that ignores SIGTERM: after kill it still held the port, and after kill -9 it was gone. Use -9 as the last resort, because the process gets no chance to clean up.
sudo fuser -k -n tcp 8080 # kills whatever holds the port (SIGKILL by default) fuser -k worked (listener gone afterwards), but it sends SIGKILL by default, so use it only when you are sure what owns the port. To avoid killing the wrong thing, run fuser -v first and read the command.
Errors you will see
| Message | Meaning | First check |
|---|---|---|
[Errno 98] Address already in use (EADDRINUSE in Node) | Another listener, or TIME-WAIT without reuse | ss -tanp 'sport = :PORT' |
[Errno 13] Permission denied on port 80 | Unprivileged user binding a port below 1024 | See below |
| Works locally, not remotely | Bound to 127.0.0.1, or firewall | Local Address column |
The permission case: as nobody, binding port 80 failed with [Errno 13] Permission denied. On this machine /proc/sys/net/ipv4/ip_unprivileged_port_start was 1024, so ports below that need root or a capability. Not an "in use" problem at all. Run the service on a high port behind a reverse proxy, or grant the binary the CAP_NET_BIND_SERVICE capability; I did not test the capability route.
Other platforms
These I did not run: on macOS, lsof -nP -iTCP:8080 -sTCP:LISTEN should work as on Linux, but ss is not available. On Windows the usual pair is netstat -ano | findstr :8080 then tasklist /FI "PID eq <pid>". The older netstat -tlnp on Linux needs the net-tools package, which was not installed on my test system; prefer ss.
Checklist
sudo ss -ltnp 'sport = :PORT'- Empty? Try
ss -tan 'sport = :PORT'for TIME-WAIT, and check you usedsudo. - Identify it with
ps -o pid,user,etime,args -p PID. - Stop the owning service, or
kill PID, thenkill -9only if it ignores that. - Confirm with
ssand start your server. - If it works locally but not remotely, read the Local Address column.
Frequently asked questions
How do I find which process is using port 8080 on Linux?
Run sudo ss -ltnp 'sport = :8080' or sudo lsof -nP -iTCP:8080 -sTCP:LISTEN.
Why does lsof show nothing but the port is still in use?
Either you lack the privileges to see the owner (use sudo), or the port is in TIME-WAIT with no process attached. ss -tan shows the latter.
How long does TIME-WAIT last?
About 60 seconds in my test on Linux.
Is it safe to use fuser -k?
It sends SIGKILL by default, so the process cannot clean up. Check the owner with fuser -v first, and prefer stopping the service properly.
Should I use netstat or ss?
Use ss. It is installed by default with iproute2 on current distributions, while netstat needs an extra package.
update log
- 19 November 2026: first version.
- To recheck: ss and lsof output formats on new distribution releases.
Sources
- iproute2 (ss) project page
- lsof project
- psmisc project (fuser)
- socket(7) manual page (SO_REUSEADDR)
- tcp(7) manual page
Originally published on DEV Talk.