• Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
  • Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
Home»Distros»Ubuntu»How To Kill A Process On Ubuntu

How To Kill A Process On Ubuntu

Anup ThapaBy Anup ThapaApril 7, 2023 Ubuntu 3 Mins Read

Some processes can cause memory leaks and lead to system performance degradation. For instance, VLC is known to have this problem. Leaving aside memory leaks, you might sometimes need to manually kill a process that’s not responding. There are different ways to do this; some more graceful than others.

Should You Stop, End, or Kill a Process?

You can list the various signals you can send to a process with

kill -l

The ones relevant to us are SIGHUP (1), SIGINT (2), SIGKILL (9), SIGTERM (15), and SIGSTOP (19).

  • SIGHUP (1) – Sends a signal that the controlling terminal or process hanged up. This’ll usually cause the process to shut down.
  • SIGINT (2) – Send an interrupt signal to the process.
  • SIGKILL (9) – Immediately kill the process. 
  • SIGTERM (15) – Gracefully terminate a process, giving it the chance to perform cleanup tasks before shutting down.
  • SIGSTOP (19) – Stop the process in its current state.

SIGSTOP only pauses the process. Sometimes that’s useful, but when you need to actually kill the process, it’s not relevant.

SIGTERM allows a process to run any appropriate handlers to terminate properly, whereas SIGKILL abruptly kills a process.

Due to data loss and inconsistency concerns, we recommend using SIGTERM whenever possible.

Kill with System Monitor

The System Monitor allows you to graphically manage processes through an easy-to-use applet. 

  1. Search and open ‘System Monitor’ and right-click the process to manage.
    system monitor ubuntu
  2. Stop (SIGSTOP), End (SIGTERM), or Kill (SIGKILL) the process as appropriate.
    kill process ubuntu system monitor

Get PID and Kill Process

There are a couple of easy ways to get the process ID (PID) of the process you want to kill. First, you could name the program with pidof.

pidof firefox

You can also use the ps command to list every active process on the system, then filter the output with grep.

ps -ef | grep firefox

Once you know the PID, you can use the following format to kill the specified processes.

sudo kill pid
sudo kill 12756 5532

By default, this will send the TERM (15) signal. If you want to send a KILL (9) or some other signal instead, you can do so by specifying the signal name or number. Any of these formats will have the same effect.

sudo kill -9 12756
sudo kill -KILL 12756
sudo kill - SIGKILL 12756

Kill Processes with killall

Some programs might spawn hundreds of processes, and trying to kill each one individually isn’t very practical. Instead, you can use the killall command to kill all processes related to the specified name.

sudo killall firefox

By default, this sends SIGTERM. If you want to send a different signal, you can specify it with the -s option.

sudo killall -s 9 firefox

killall also has other useful options such as the process-group (-g) flag, which kills the process group to which the process belongs, or the user (-u) flag, which kills processes owned by the specified user.

Use htop to Find and Kill Processes

htop is an interactive process manager that can also be used to kill processes. On new systems, you might need to install it first.

sudo apt install htop
  1. Launch it by entering htop and press F3 to search for the process. Press F3 again and cycle through the listed processes.
    htop search process
  2. While the process is selected, press F9 twice. Select the signal to send and press Enter.
    htop send kill signal
Anup Thapa
  • LinkedIn

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. At LinuxStart, Anup is an integral part of our editorial team. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys experimenting with different Linux distros and reading up on things like networking and virtualization.

Leave A Reply Cancel Reply

Table of Contents
  • Should You Stop, End, or Kill a Process?
  • Kill with System Monitor
  • Get PID and Kill Process
  • Kill Processes with killall
  • Use htop to Find and Kill Processes
Linux Start
Guides

What is the Linux Kernel?

The Linux Kernel is the core of the Linux operating system and is central to…

How To Install Linux Mint

How To Install Linux on VirtualBox

Getting Started with Linux

How to Install Linux

10 Best Linux Distros of 2023

Which Linux Distro Should You Choose? A Complete Guide to Help You Decide

© 2023 LinuxStart.com

Type above and press Enter to search. Press Esc to cancel.