> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Kill a Process on Linux (kill, pkill and killall)

> Kill a process on Linux: find its PID with pgrep -a name or ps aux, then run kill PID. If it won't stop, use kill -9 PID. Also pkill, killall and stuck services.

To kill a process on Linux, find its process ID (PID) with `pgrep -a python` or `ps aux | grep python`, then run `kill 12345`. That sends SIGTERM, which asks the program to close cleanly. If it is still running after a few seconds, force it with `kill -9 12345` (SIGKILL). Use `sudo` for processes owned by other users, and stop services with `systemctl stop` rather than `kill`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Every Linux distribution | sudo for other users' processes |

## Before you start

* [Connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md).
* You can kill your own processes. Processes owned by root or other users need `sudo` (root can leave it out).
* If the program is a **service** (nginx, MariaDB, a game server unit), use `sudo systemctl stop name` or `restart`. systemd restarts many killed services automatically. See [manage services with systemctl](https://help.freakhosting.com/portals/other/how-to-manage-services-with-systemctl.md).

## How to find the process ID (PID)

> [tab] By name
>
> ```bash theme={null}
> pgrep -a python3
> ```
>
> ```text theme={null}
> 30043 python3 -m http.server 8080
> ```
>
> The first number is the PID.

> [tab] With ps
>
> ```bash theme={null}
> ps aux | grep '[h]ttp.server'
> ```
>
> ```text theme={null}
> alex     30043  3.8  0.2  27024 19648 ?   S  13:28  0:00 python3 -m http.server 8080
> ```
>
> The PID is the second column. The `[h]` trick stops `grep` from listing itself.

> [tab] By port
>
> ```bash theme={null}
> sudo lsof -i :8080 -P -n
> sudo ss -tlnp 'sport = :8080'
> ```
>
> See [check open ports](https://help.freakhosting.com/portals/other/how-to-check-open-ports-on-linux.md).

> [tab] By resource use
>
> ```bash theme={null}
> ps -eo pid,user,%cpu,%mem,cmd --sort=-%cpu | head
> ```
>
> Lists the processes using the most CPU. Use `--sort=-%mem` for memory, or open `top` / `htop`.

## How to kill a process by PID

**1. Ask it to stop**

```bash theme={null}
kill 30043
```

This sends **SIGTERM** (signal 15). The program can save its work and close.

**2. Check it is gone**

```bash theme={null}
ps -p 30043
```

If only the header line prints, the process has ended.

**3. Force it if needed**

If it is still running after 5 to 10 seconds:

```bash theme={null}
kill -9 30043
```

**SIGKILL** (signal 9) stops it instantly. The program can't clean up, so unsaved data is lost.

> [!WARNING]
>
> Use `kill -9` as a last resort. A database or game server killed this way can lose recent data or corrupt files; stop those through their own command or `systemctl stop`. Never kill PID 1 (`systemd`), `sshd` while you are connected through it, or processes you don't recognise on a production server.

### Common signals

| Signal | Number | Use |
| - | - | - |
| `SIGTERM` | 15 | Default. Ask to stop cleanly |
| `SIGKILL` | 9 | Force stop; can't be caught or ignored |
| `SIGHUP` | 1 | Many daemons reload their config |
| `SIGINT` | 2 | Same as pressing `Ctrl+C` |

Use the name or the number: `kill -HUP 1204` and `kill -1 1204` are the same. `kill -l` lists all signals.

## How to kill a process by name

```bash theme={null}
pkill -f "http.server 8080"   # match the full command line
pkill python3                 # match the process name
killall python3               # every process with exactly this name
```

`pkill` and `killall` send SIGTERM too; add `-9` to force.

> [!WARNING]
>
> Name matching can hit more than you expect. `pkill -f` matches anywhere in the command line, including other users' processes (with `sudo`) and even the shell that runs the command. Always preview first with `pgrep -a -f "pattern"`, check the list, then run `pkill` with the same pattern.

On AlmaLinux and Rocky Linux, `killall` comes from the `psmisc` package: `sudo dnf install psmisc`.

## What to do if a process won't die

| Situation | What it means | What to do |
| - | - | - |
| Still running after `kill -9` | Process is in state `D` (waiting for disk or network I/O) | Wait, fix the storage or network issue, or reboot |
| Shows as `<defunct>` (state `Z`) | A zombie: already dead, waiting for its parent | Restart or kill the **parent** (`ps -o ppid= -p PID`) |
| Comes back with a new PID | systemd, a supervisor or cron restarts it | `systemctl stop` the service, or remove the cron job |
| `Operation not permitted` | Owned by another user | Use `sudo kill PID` |

Check the state with `ps -o pid,stat,cmd -p 30043`. The `STAT` column shows `D`, `Z`, `S` (sleeping) or `R` (running).

## How to check it worked

```bash theme={null}
pgrep -a python3 || echo "no process running"
```

If nothing matches, you see `no process running`. If you killed a program to free a port, `sudo ss -tlnp 'sport = :8080'` should show only the header line.

## Frequently asked questions

### What is the difference between kill, pkill and killall?

`kill` takes a PID. `pkill` takes a pattern and matches part of the name (or the full command line with `-f`). `killall` matches the exact process name.

### How do I kill all processes of one user?

Run `sudo pkill -u alex` to send SIGTERM to all of alex's processes. This also ends their SSH sessions.

### How do I kill a process that is using a port?

Find it with `sudo lsof -i :8080 -t` (prints only the PID) and kill it: `sudo kill $(sudo lsof -i :8080 -t)`. Check the PID first if it might be a service.

### My server is out of memory and processes keep getting killed. Why?

That is the kernel's out-of-memory (OOM) killer. See [fix out of memory killed processes](https://help.freakhosting.com/portals/other/how-to-fix-out-of-memory-killed-processes.md) and [check memory usage](https://help.freakhosting.com/portals/other/how-to-check-memory-usage-on-linux.md).

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Monitor resources with htop](https://help.freakhosting.com/portals/other/how-to-monitor-server-resources-with-htop.md)
>
> Find and kill processes visually.

> [card] [Find what is using CPU](https://help.freakhosting.com/portals/other/how-to-find-what-is-using-cpu-on-linux.md)
>
> Track down a busy process.

> [card] [Manage services with systemctl](https://help.freakhosting.com/portals/other/how-to-manage-services-with-systemctl.md)
>
> Stop services the right way.

> [card] [Check open ports](https://help.freakhosting.com/portals/other/how-to-check-open-ports-on-linux.md)
>
> Find what holds a port.

***

> [!NOTE]
>
> **Checked against the [kill(1)](https://man7.org/linux/man-pages/man1/kill.1.html), [pkill(1)](https://man7.org/linux/man-pages/man1/pkill.1.html) and [signal(7)](https://man7.org/linux/man-pages/man7/signal.7.html) manuals** on 4 November 2026; commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.