Step 1: Find the Process
sudo ss -ltnp 'sport = :8080'
-l shows listening sockets, -t TCP, -n numbers instead of names, and -p the process. The last column names the program and its PID, in a form like users:(("node",pid=2481,fd=21)). Without sudo, ss cannot show processes of other users and leaves that column empty. For a UDP port, use -lunp. A simpler filter that also works: sudo ss -ltnp | grep ':8080'. The ss command guide explains the rest of the output.
Other Ways to Find It
sudo lsof -i :8080
sudo lsof -t -i :8080 -sTCP:LISTEN
sudo fuser 8080/tcp
lsof prints the command, PID, and user; with -t it prints only PIDs, and -sTCP:LISTEN limits the result to the listening process. More in the lsof command guide. fuser prints the PIDs that use the port; it comes from the psmisc package, which some minimal installs lack. For an overview of every open port, see how to check open ports in Linux.
Step 2: Check Whether It Is a Service
systemctl status 2481
Given a PID, systemctl shows the unit the process belongs to. If it is a service, killing the PID solves nothing: systemd may restart it at once, and it starts again at the next boot. Stop it, and disable it if it should not run at all:
sudo systemctl stop apache2
sudo systemctl disable apache2
A common case is Apache and Nginx both wanting port 80. See the systemctl command for the rest.
Step 3: Stop a Process That Is Not a Service
Start with a normal kill, which sends SIGTERM and lets the program close its files and finish writing:
kill 2481
sleep 5
sudo ss -ltnp 'sport = :8080'
Use sudo for a process of another user. A warning about the last resort: kill -9 sends SIGKILL, which the program cannot handle, so unsaved data is lost and lock or temporary files can stay behind. Use it only when the process ignores SIGTERM, and never as a first step on a database. The signals are compared in how to kill a process in Linux.
kill -9 2481
One-Line Forms
sudo lsof -t -i :8080 -sTCP:LISTEN
sudo kill $(sudo lsof -t -i :8080 -sTCP:LISTEN)
sudo fuser -k -TERM 8080/tcp
Run the first line alone before the second, to see which PIDs it would hit. Without -sTCP:LISTEN, lsof also returns local programs connected to that port as clients. fuser sends SIGKILL with -k unless you name another signal, which is why the third line adds -TERM.
Ports Held by Docker
If ss names docker-proxy, or the port answers while no host program seems to own it, a container has published it. Find the container in the PORTS column:
docker ps
docker stop web
A container with a restart policy comes back with the Docker service; change the policy as described in Docker restart policy. The listing itself is explained in docker ps, and publishing in Docker port mapping.
When the Port Is Still Busy
- Something restarts it: a process manager such as PM2, a cron
@rebootjob, or another unit. Find the parent withps -o ppid= -p PID, as shown in the ps command. - TIME-WAIT entries:
ss -tanmay still list connections after the program ended. They belong to no process and clear by themselves. - IPv4 and IPv6: a program can listen on
0.0.0.0:8080and[::]:8080separately; check both lines in the ss output.