Video in progress

If port 8080 is busy on a Linux server, how do you find which process holds it?

ss -ltnp | grep 8080 or lsof -i :8080 shows the PID and name of the process listening on the port. Then you check what that PID actually is.

📖 Answer

The app fails on startup with "Port 8080 was already in use". The first step:

sudo ss -ltnp | grep :8080
# LISTEN 0 100 *:8080 *:* users:(("java",pid=21347,fd=45))

sudo lsof -i :8080        # alternative
ps -fp 21347              # which java is this?

The ss flags: l means only listening sockets, t is TCP, n is numeric (no DNS), p is the process. You need sudo, otherwise you will not see the name of another user's process.

In practice it is often an old copy left over from the previous deploy. Before you kill it, make sure: the command line that ps prints shows the jar name and path. The old netstat -tulpn works too, but on newer distros it is sometimes not installed.