Hi everyone. Every Linux user eventually meets a program that will not close, or a background job that keeps the CPU busy for no reason. On a desktop you can sometimes click the close button, but in a terminal or on a server the reliable way is to find the process and send it a signal. In this guide I do exactly that on Ubuntu 26.04 with ps, pgrep, kill, and pkill.
To keep the practice safe, I created my own runaway processes instead of killing real programs: a sleep that waits for 1000 seconds, yes writing endlessly into /dev/null, and a small loop that refuses the normal kill signal. Each one shows a different situation you will meet in real life.
If you have not read it yet, the previous article on the systemctl command covers background services. For those, stop them with systemctl instead of killing their process, otherwise systemd may simply start them again.
Distro : Ubuntu 26.04.1 LTS (Desktop)
Tools : ps, pgrep, pidof, kill, pkillCreating Test Processes
Practicing kill on real programs is a bad idea, because the wrong PID can close your desktop session or lose unsaved work. Making your own disposable processes lets you see each signal at work without any risk.
Both test commands below are started with & at the end, which runs them in the background and gives the prompt back immediately. The shell prints a job number in brackets and the process ID, the PID, which is the number kill needs.
Start sleep and yes in the background

sleep 1000 &
yes > /dev/null &
jobs -lsleep got job [1] with PID 7977 (number 1), and yes got job [2] with PID 7979 (number 2). jobs -l lists both as Running together with their PIDs (number 3). jobs only shows processes started from this terminal, so for anything else you need ps or pgrep.
Finding the Process to Stop
The first step is always to find the right process, not to kill something quickly. Several programs can have similar names, and a mistake here stops the wrong thing.
ps shows every process with its owner, CPU and memory use, while pgrep and pidof are shortcuts that return only the PID for a name. Use ps when you are looking for the culprit, and pgrep when you already know its name.
ps sorted by CPU

ps aux --sort=-%cpu | head -n 4 | cut -c 1-100–sort=-%cpu puts the busiest process at the top, head keeps the first lines, and cut trims long command lines to fit the screen. The header explains each column (number 1). yes is at the top with PID 7979 and 100 percent of one CPU core (number 2). This is what a runaway process looks like.
pgrep and pidof

pgrep -a yes
pgrep -a sleep
pidof yespgrep -a prints the PID together with the full command, 7979 yes (number 1) and 7977 sleep 1000 (number 2). pidof gives only the number (number 3), which is handy inside another command.
Stopping a Process with kill
kill does not actually kill anything by itself. It sends a signal, and by default that signal is SIGTERM, a polite request to finish. Well-behaved programs close their files and exit when they receive it.
That is why plain kill should always be your first try. It gives the program a chance to clean up, and in most cases it is all you need.
kill with the PID

kill $(pidof yes)
jobs -l$(pidof yes) is replaced by 7979, so this is the same as typing kill 7979. The shell reports job [2] as Terminated (number 1), and jobs -l now lists only sleep (number 2). CPU use drops back to normal right away.
When kill Is Not Enough
Some processes catch SIGTERM and keep running, either because they are stuck or because they were written to ignore it. To see this, I started a small loop that runs : (do nothing) whenever it receives SIGTERM.
In this case the next step is kill -9, which sends SIGKILL. A process cannot catch or ignore SIGKILL, the kernel removes it immediately. The trade-off is that the program gets no chance to save anything.
A process that ignores SIGTERM

bash -c 'trap : TERM; while :; do sleep 1; done' &
sleep 1; kill %2
sleep 2; jobs -l%2 means job number 2, so I did not need the PID. The kill only ended the short sleep 1 running inside the loop, which shows as Terminated sleep 1 (number 1). Two seconds later the job itself is still Running (number 2).
kill -9

kill -9 %2
sleep 1; jobs -lThis time the shell reports Killed instead of Terminated (number 1), the sign that SIGKILL was used. Only the sleep 1000 job is left (number 2).
Warning: Use kill -9 only after a normal kill did not work. A program killed this way cannot save files or clean up temporary data.
Stopping Processes by Name with pkill
Looking up a PID first is fine for one process, but sometimes you need to stop every copy of a program, for example ten stuck browser helpers. pkill does the search and the kill in one step.
Because pkill matches names, it can also hit more than you expect. Run pgrep -a with the same pattern first to see what will be stopped, and use -x for an exact name match.
pkill -x

pkill -x sleep
sleep 1; pgrep -a sleep; echo exit code $?pkill sent SIGTERM to every process named exactly sleep, and the background job reports Terminated sleep 1000 (number 1). pgrep found nothing and returned exit code 1, which means no match (number 2).
Common Problems and How to Fix Them
kill has only a few error messages, and they tell you exactly what went wrong. The two you will see most often are about a PID that does not exist and a process that belongs to someone else.
To see which signals exist, kill -l lists them all. In daily use you only need 15 (SIGTERM, the default) and 9 (SIGKILL).
kill errors and the signal list

kill 99999
kill 1
kill -l | head -n 2No such process means the PID does not exist, usually because the program already ended or the number was mistyped (number 1). Operation not permitted means the process belongs to another user, here PID 1, which is systemd and belongs to root (number 2). kill -l shows the numbered signals, including 9) SIGKILL (number 3).
Operation not permitted
The process belongs to root or another user. Use sudo kill, but only when you are sure it is the right process.
No such process
The PID is wrong or the process already exited. Check again with pgrep -a.
The process comes back after kill
It is probably a service managed by systemd. Stop it with sudo systemctl stop instead.
That covers stopping processes on Linux: find them with ps, pgrep, and pidof, stop them politely with kill, force them with kill -9, and stop them by name with pkill. Next in the series is monitoring processes live with top and htop. If kill or pkill shows a message I did not cover, paste it in the comments.












