↑↓ move Enter open Esc close

How to Kill the Process Using a Port in Linux

Find which process holds a port and stop it cleanly.

You start your app and get "address already in use". Something is already listening on that port, and in development it is almost always a previous instance of the same program that never shut down. Two steps: identify the owner, then stop it politely.

Step by step

1 Find what holds the port

$ sudo ss -tlnp | grep :3000

The last column shows the process name and PID, like users:(("node",pid=12345,fd=23)). Without sudo you only see your own processes, which is often enough in development.

2 Stop it politely

$ kill 12345

Sends SIGTERM, which asks the program to shut down cleanly: flush buffers, close files, exit. Give it a couple of seconds before escalating.

3 One-liner when you are sure

$ kill $(sudo lsof -t -i:3000)

lsof -t prints bare PIDs, which feed straight into kill. Check what it matches first with lsof -i:3000 if the port might belong to something important.

4 Force it only if it ignores you

$ kill -9 12345

SIGKILL cannot be caught: the kernel removes the process immediately, with no chance to save state or clean up. Correct as a last resort, wrong as a habit.

5 If it is a real service, stop it properly

$ sudo systemctl stop nginx

Killing a managed service can leave systemd trying to restart it. Use its manager instead, and consider whether your app should use another port.

Tips worth knowing

Frequently asked questions

ss or lsof, which should I use?

ss is faster and installed by default on modern systems. lsof is more flexible and reads well (lsof -i :3000). Both answer this question fine.

Is it safe to kill the process?

If it is your own leftover instance, yes. If it turns out to be a system service like nginx or postgresql, stop it through systemctl instead.

Nothing shows up but the port is still busy

Try with sudo: the owner may be another user. Also check Docker containers, and remember that IPv6 and IPv4 bindings are listed separately.

If it goes wrong

The commands behind it

Concepts involved: Port · PID (Process ID)

More how-to guides