Skip to main content
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.

Before you start

  • Connect with SSH.
  • 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.

How to find the process ID (PID)

The first number is the PID.

How to kill a process by PID

1

Ask it to stop

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

Check it is gone

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:
SIGKILL (signal 9) stops it instantly. The program can’t clean up, so unsaved data is lost.
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

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

pkill and killall send SIGTERM too; add -9 to force.
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

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

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 and check memory usage.

VPS and dedicated server guides

Every server guide in one place.

Monitor resources with htop

Find and kill processes visually.

Find what is using CPU

Track down a busy process.

Manage services with systemctl

Stop services the right way.

Check open ports

Find what holds a port.

Checked against the kill(1), pkill(1) and signal(7) manuals on 4 November 2026; commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026