Linux Commands

How To Kill a Process in Linux

Whether you launch the file manager, run a system service, or execute a command in the terminal, each action initiates a process. These processes run in the foreground or background while consuming system resources such as memory, CPU, and disk space. Therefore, processes essential to ensure appropriate functioning of the system.

Moreover, users sometimes need to terminate processes for reasons like an unresponsive application, a software update, security concerns, etc. So, this guide will briefly explain the methods you can use to kill a process in Linux using suitable examples. Linux has three commands– kill, pkill, and killall, to kill processes. Let’s divide this section further to discuss each of these commands one at a time.

The kill Command

If you want to terminate a process gracefully, do it using the kill command:

kill PID

Replace PID with the process ID you want to remove. This will send the kill signal to that process. For example, let’s eliminate PID 3906 using the kill command:

kill 3906

Please remember that on successful execution, these commands(including those mentioned below) return nothing.

The pkill Command

You can use the pkill to eliminate a process using its name. If an application has multiple processes running, you can kill them all using the pkill command.

pkill process_name

kill-command-in-linux

Here, putting the application name in place of the term process_name will kill all the processes matching to it. To kill the processes initiated by the Firefox browser, you must enter the following command:

pkill firefox

pkill-command-in-linux

The killall Command

If a process has various sub-processes running, please run the pkill command to kill them all.

pkill process_name

Putting the application name in place of the term process_name will kill all the processes matching it. To kill the processes initiated by the Firefox browser, you must enter the following command:

killall firefox

killall-command-in-linux

A Quick Wrap-up

Killing processes in Linux is fundamental, and it helps you maintain a healthy system. It assists you in troubleshooting unresponsive applications, resource optimization, etc. This guide outlines all the three commands you can use to kill processes. The kill command helps you while working with the process IDs, whereas the pkill and killall commands come in handy for process names.

About the author

Prateek Jangid