Knowledge

How to kill the process running on a port in Linux

#CommandLine

Find the PID listening on a port with lsof, ss or netstat, then kill it cleanly, with one-liner shortcuts using kill, fuser and lsof.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. When a port is stuck
  2. Find the process listening on the port
  3. Kill the process
  4. The one-liners I actually use
  5. A quick word of caution

When a port is stuck

You try to start your dev server and Linux tells you the port is taken. Before you can free it, you need to find which process is holding the port, get its PID (process ID), and stop it. Here's how I do it. If you hit the classic address already in use error, this is exactly the fix.

Find the process listening on the port

My favorite is lsof, which lists open files (and sockets count as files):

lsof -i :3000

The -i :3000 filters to the network connection on port 3000. The output's PID column is the number you need. If you prefer the modern socket tool, ss works too:

ss -ltnp 'sport = :3000'

Those flags read as -l listening sockets, -t TCP, -n numeric ports (don't resolve names), -p show the owning process. The older netstat does the same job if it's installed:

sudo netstat -tulpn | grep :3000

Here -t is TCP, -u UDP, -l listening, -p process, -n numeric. You usually need sudo to see PIDs owned by other users.

Kill the process

Once you have the PID, send it a termination signal:

kill 12345

Plain kill sends SIGTERM, which asks the process to shut down gracefully. That's what you want most of the time. If it ignores you and refuses to die, escalate to SIGKILL, which the process cannot catch or ignore:

kill -9 12345

Reach for -9 only when a normal kill doesn't work, because the process won't get a chance to clean up.

The one-liners I actually use

Looking up the PID and typing it back in gets old fast. lsof -t prints only the PID, so you can feed it straight into kill:

kill $(lsof -t -i:3000)

Even shorter, fuser can find and kill in a single command:

fuser -k 3000/tcp

The -k flag kills every process attached to that port, and 3000/tcp scopes it to TCP port 3000. To send SIGKILL instead, add -9:

fuser -k -9 3000/tcp

A quick word of caution

Before you kill blindly, glance at what's actually using the port, especially with sudo. Killing the wrong PID can take down a database or a service you didn't mean to touch. When in doubt, run lsof -i :3000 first and read the command name before pulling the trigger.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

Argument list too long (Bash: /bin/rm)

Find the PID listening on a port with lsof, ss or netstat, then kill it cleanly, with one-liner shortcuts using kill, fuser and lsof.

Read more →

How to install Composer packages locally

Find the PID listening on a port with lsof, ss or netstat, then kill it cleanly, with one-liner shortcuts using kill, fuser and lsof.

Read more →