SysadminGuide

How to kill the process using a port on Linux

On this page
  1. Step 1: find the PID on the port
  2. Step 2: stop it cleanly (SIGTERM)
  3. Step 3: force it only if needed (SIGKILL)
  4. The one-liner
  5. When lsof shows nothing

When a port is already in use on Linux and you hit the dreaded 'address already in use', the job is to find the process holding the port and stop it. sudo lsof -i :8080 (or ss -ltnp on a leaner box) prints the PID listening on the port; send it a polite kill PID first, and fall back to kill -9 only if it ignores you. Here's how to read the lsof output, the difference between SIGTERM and SIGKILL and why the gentle one comes first, a fuser one-liner that finds and kills in a single command, and what to check when the port looks busy but lsof shows nothing at all.

The short answer

sudo lsof -i :8080 (or ss -ltnp) shows the PID holding the port. Stop it cleanly with kill 4821, and use kill -9 4821 only if it refuses to go. The “address already in use” error clears the moment the process exits.

lsof -ifind the PID
kill / -9gentle, then forced
fuser -kthe one-liner
Answer card showing sudo lsof -i :8080 to find the PID on a port, then kill to free it, on Linux.
Find the PID, stop it gently, force it only if you must. PNG

Step 1: find the PID on the port

Linux
sudo lsof -i :8080

The PID column is the one you want. No lsof on this box? Two alternatives do the same job: sudo ss -ltnp | grep :8080, or sudo fuser 8080/tcp, which prints just the PID.

Step 2: stop it cleanly (SIGTERM)

Linux
kill 4821

Plain kill sends SIGTERM, which asks the process to shut down and lets it close files and free the port properly. Give it a second, then re-run the lsof from Step 1 to check it is gone.

Step 3: force it only if needed (SIGKILL)

If the process ignores SIGTERM and still holds the port, escalate:

Linux
kill -9 4821

kill -9 sends SIGKILL, which cannot be caught or ignored. It is the last resort, not the first move, because the process gets no chance to clean up.

Terminal showing sudo lsof -i :8080 finding node on PID 4821, then kill 4821 and kill -9 4821 as a fallback.
lsof to find it, kill to stop it, kill -9 only when it digs in. PNG

The one-liner

Once you trust what is on the port, find and kill it in a single command:

Linux
sudo fuser -k 8080/tcp

The lsof equivalent is sudo kill -9 $(sudo lsof -t -i:8080).

When lsof shows nothing

If the port seems busy but lsof is empty, two things to check. The socket may be in TIME_WAIT, cooling down after a close, in which case no process holds it and it frees itself shortly. Or the owning process belongs to root and you forgot sudo, so you simply could not see it.

On Windows instead? The tools are netstat and taskkill: see how to kill the process using a port on Windows.

Frequently asked questions

How do I find which process is using a port on Linux?

Run "sudo lsof -i :8080" to see the program and PID bound to the port. "sudo ss -ltnp | grep :8080" does the same without lsof installed, and "sudo fuser 8080/tcp" prints just the PID.

What is the difference between kill and kill -9?

Plain kill sends SIGTERM, asking the process to shut down cleanly and free its resources. kill -9 sends SIGKILL, which the process cannot catch or ignore: it dies instantly but gets no chance to clean up. Always try SIGTERM first.

Why do I need sudo to kill the process?

If the process runs under another user or as root (as many services do), you can only see and kill it with elevated rights. For a process you started yourself, sudo is not required.

Is there a one-liner to free a port?

Yes: "sudo fuser -k 8080/tcp" finds and kills whatever holds the port in one command. "sudo kill -9 $(sudo lsof -t -i:8080)" does the same with lsof. Use them once you are sure what is on the port.