Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Stop a Linux process

By updated

Improve this page

When a program no longer responds or uses too many resources, you have to stop it. Linux uses a system of signals to talk to processes. The kill command sends these signals and, despite its name, it does not always kill: it asks politely first.

What you will learn

  • Stop a process cleanly with kill
  • Force a stop with kill -9
  • Understand the signals SIGTERM, SIGKILL and SIGINT
  • Target a process by name with killall and pkill
  • Get back control of a blocked terminal

Which signals should you know?

A signal is a message sent to a process to ask it to act. Here are the three to know:

SignalNumberEffect
SIGTERM15Clean stop request (the process can save and close)
SIGKILL9Immediate, forced stop (the process cannot ignore it)
SIGINT2Interruption (same as Ctrl+C)

How do you stop a process with kill?

kill sends a signal to a process identified by its PID.

  1. Find the PID of the process to stop:

    Terminal window
    ps aux | grep program-name
    Example
    bob 1400 2.5 1.0 245680 98200 pts/0 S+ 10:00 0:03 python3 long-script.py

    The PID is 1400.

  2. Send SIGTERM (clean stop):

    Terminal window
    kill 1400
  3. Check that the process is gone:

    Terminal window
    ps -p 1400

    If only the header line shows, the process has ended. Avoid ps aux | grep 1400 for this check: the line of the grep itself contains 1400 and makes you believe the process is still running.

  4. If the process is still there, force it with SIGKILL:

    Terminal window
    kill -9 1400

kill syntax

Terminal window
kill PID # Sends SIGTERM (signal 15): the default
kill -15 PID # Same thing: explicit SIGTERM
kill -9 PID # Sends SIGKILL: forced stop
kill -SIGTERM PID # Same thing with the signal name

How do you interrupt the current process with Ctrl+C?

When a program runs in the foreground of your terminal:

ShortcutSignal sentEffect
Ctrl+CSIGINT (2)Interruption request
Ctrl+ZSIGTSTP (20)Suspends the process (does not stop it)
Ctrl+\SIGQUIT (3)Stop with a core dump (last resort)

In most situations, Ctrl+C is enough.

How do you stop processes by name with killall?

killall targets every process carrying a given name:

Terminal window
# Stop every "firefox" process
killall firefox
# Force the stop
killall -9 firefox

How do you stop processes with a pattern using pkill?

pkill is more flexible, it accepts a partial pattern:

Terminal window
# Stop the processes whose name contains "python"
pkill python
# Stop the processes of a given user
pkill -u alice

The difference between killall and pkill:

CommandMatching
killall firefoxExact name: firefox
pkill firePartial pattern: anything containing fire

How do you get back control of a blocked terminal?

When your terminal seems blocked, try these moves in this order:

  1. Ctrl+C, which interrupts the foreground process

  2. Ctrl+Z, which suspends the process (then kill %1 to end it)

  3. If nothing responds, open a second terminal and find the PID:

    Terminal window
    ps aux | grep your-command
  4. From the second terminal:

    Terminal window
    kill PID
  5. As a last resort:

    Terminal window
    kill -9 PID

Practical examples

Three situations cover most of what you will do with these commands: a development server left running, several instances of a script, and the final check that a process is really gone.

Stop a development web server

A development server started in the foreground stops with Ctrl+C. But when it runs in the background or in another terminal, you must find its PID before stopping it. The sequence below illustrates the common case: you identify the process by its command line, then send it a SIGTERM for a clean stop.

Terminal window
# Find the PID of the server
ps aux | grep "python3 -m http.server"
# Result: PID 2100
kill 2100

Stop every process of a script

Terminal window
# Several instances of script.sh are running
pkill -f "script.sh"

The -f option searches the full command line, not only the process name.

Check that a process has really stopped

Terminal window
# After kill
ps -p 2100

If the process is gone, only the header line shows and the exit code is 1 on the version of ps tested (check it on your machine with echo $?, the value can vary with the version). Otherwise, its line appears under the header.

Command summary

This table condenses the whole guide into a cheat sheet. Keep in mind the progression it implies: you go from the gentlest (SIGTERM, Ctrl+C) to the most brutal (SIGKILL), and from the most precise (a PID) to the broadest (killall, pkill). When in doubt, always start with the top line.

CommandAction
kill PIDSends SIGTERM to the process (clean stop)
kill -9 PIDSends SIGKILL (forced stop)
killall nameStops every process named exactly name
pkill patternStops the processes matching the pattern
pkill -f "command"Searches the full command line
Ctrl+CInterrupts the foreground process
Ctrl+ZSuspends the foreground process

Troubleshooting

When a kill has no effect, the cause is almost always one of the five lines below. The useful reflex is to read the reason before forcing: a process that ignores SIGTERM is dealt with by SIGKILL, but a process in state D (waiting on disk or network) answers no signal, and insisting is useless until the blocking access is resolved.

SymptomLikely causeFix
kill PID does nothingThe process ignores SIGTERMWait a few seconds, then kill -9 PID
kill: (PID) - Operation not permittedThe process belongs to another userUse sudo kill PID
killall does not find the processThe name does not match exactlyUse pkill with a partial pattern
A zombie process persistsThe parent has not collected the exit codeKill the parent process or wait
kill -9 does not workProcess in state D (kernel I/O wait), very rareSolve the I/O problem (disk, network) or reboot

Key points

  • SIGTERM (kill PID) asks for a clean stop: always try it first.
  • SIGKILL (kill -9 PID) forces the stop: a last resort.
  • Ctrl+C sends SIGINT to the foreground process.
  • killall targets an exact name, pkill a partial pattern.
  • Always check with ps -p that the process has really gone.

Knowledge check

Check that the essentials of this guide stuck. The questions cover only what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer