How to kill the process running on a port in Linux - Rocketeers app

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com/login) 

 On this page

 Knowledge
---------

How to kill the process running on a port in Linux
==================================================

### [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

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](https://rocketeersapp.com/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [When a port is stuck](#content-when-a-port-is-stuck)
2. [Find the process listening on the port](#content-find-the-process-listening-on-the-port)
3. [Kill the process](#content-kill-the-process)
4. [The one-liners I actually use](#content-the-one-liners-i-actually-use)
5. [A quick word of caution](#content-a-quick-word-of-caution)

[\#](#content-when-a-port-is-stuck "Permalink")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](/address-already-in-use-port) error, this is exactly the fix.

[\#](#content-find-the-process-listening-on-the-port "Permalink")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.

[\#](#content-kill-the-process "Permalink")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.

[\#](#content-the-one-liners-i-actually-use "Permalink")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

```

[\#](#content-a-quick-word-of-caution "Permalink")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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#CommandLine](https://rocketeersapp.com/knowledge/command-line)

- [Argument list too long (Bash: /bin/rm)](https://rocketeersapp.com/knowledge/argument-list-too-long)
- [How to install Composer packages locally](https://rocketeersapp.com/knowledge/install-composer-packages-locally)
- [How to send GET and POST requests with curl](https://rocketeersapp.com/knowledge/curl-post-get-api-requests)
- [Essential Linux command line basics for developers](https://rocketeersapp.com/knowledge/linux-command-line-basics)
- [How to search file contents with grep](https://rocketeersapp.com/knowledge/search-files-grep-command)
- [The complete guide to the curl command](https://rocketeersapp.com/knowledge/curl-command-complete-guide)

 [View all 21 articles →](https://rocketeersapp.com/knowledge/command-line)
