Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Kill a Process in Linux from the Command Line

Find a process ID and end the process with kill, killall, pkill or top.

How-To Guides2 min read4 steps5 screenshots

Why kill a process

  1. It does not respond. The process hangs.
  2. It uses too many resources. CPU, memory or disk are full.
  3. It misbehaves, or it is a security risk.
  4. You are debugging and need a clean state.

Find the process ID (PID)

pgrep firefox
Finding the PID with pgrep

Replace firefox with the name of the program. You can also use ps aux | grep name or pidof name.

Method 1: kill

kill [signal] PID

Example:

kill 6407
Killing a process by PID

By default kill sends the TERM signal (15), which asks the process to stop in a clean way. If it does not stop, force it:

kill -9 6407

Method 2: killall

killall ends every process with a given name:

killall [signal] process_name

Example:

killall firefox
Killing processes by name with killall

Method 3: pkill

pkill matches names with patterns:

pkill [options] pattern

Example, force-kill every match:

pkill -9 firefox

Method 4: top or htop

Start top:

top
The top command

Find the process by its PID or by its CPU and memory use. Press k, type the PID, and press Enter to send the signal.

Killing a process inside top

In htop, select the process and press F9.

Common signals

SignalNumberMeaning
SIGTERM15Ask the process to stop (default)
SIGKILL9Force the process to stop at once
SIGHUP1Hang up; many daemons reload their config
SIGSTOP19Pause the process

Precautions

  • Check the PID before you press Enter.
  • Try TERM first. kill -9 gives the process no chance to save data or clean up.
  • Do not kill system processes or essential services.
  • Use sudo only if the process belongs to another user.

FAQ

What is the difference between kill, pkill and killall? kill uses a PID. killall uses an exact name. pkill uses a pattern and more filters such as user.

A process will not die. Use kill -9 PID. A process in the D state (waiting for disk) may need a reboot.

Quick recap

  • Find the PID with pgrep, end it with kill PID.
  • Use kill -9 only when the normal signal fails.