• About Us
  • Contact us
  • Disclaimer
  • Privacy Policy

Linuxtor

Linux Tips, Tricks and DevOps Tutorials

  • Home
  • Ubuntu
  • CentOS
  • Debian
  • Commands
  • DevOps
  • Series
You are here: Home / Commands / Explain pkill command in Linux

Explain pkill command in Linux

March 9, 2022 by Asmita Leave a Comment

In the Linux systems, the pkill command is proven to be useful when you have to terminate single or multiple processes in the Linux System. This article covers the basics of pkill command and it’s options as well. pkill command can kill given running program instantly on the Linux based systems. You can specify the processes which are running either with full or partial names or using other alternative attributes.

The command pkill itself is a part of the procps package in Linux. Usually, it is the pre-installed on your system. If it’s not installed, you can install it from the Linux repository. pkill command is a wrapper command being used with a pgrep program which displays the list of processes. 

Learn how to use pkill command to terminate single or multiple process in linux.
*Using the pkill command you can terminate unwanted background processes in linux.

Table of Contents

  • 1 How to use pkill command
    • 1.1 Conclusion on pkill command

How to use pkill command

The syntax of the pkill command is below.

pkill [OPTIONS] <PATTERN>

In the above command, you have to provide [OPTIONS] and the <PATTERN> with regular expressions. The command will follow the regular expressions and act accordingly.

When running pkill without any option specified, it will send 15 (TERM) signal to the process IDs (PIDs) of all running programs that match the given name. Let’s assume you want to stop all firefox processes, then you have to run the following command.

pkill -9 firefox

If the output returns 0, it means it has at least one process available with the requested name “firefox”. If no results it will return exit code 1. These codes are very useful when used in shell scripts.

To send a different signal using the pkill command, you can use the pkill command with the option –signal with a numeric or symbolic name. Another method is to use pkill with the signal name or a number with prefix (-) hyphen.

To check all available signals, we can use the pkill -l command. Have a look, at the most commonly used signals below.

  • 1 (HUP): It is used to reload a process.
  • 9 (KILL): To kill the process.
  • 15 (TERM): To stop the process.

You can specify the signals with three different ways:

  • Use a number with a prefix. (e.g; -1)
  • Using the “SIG” prefix. (e.g; -SIGHUP)
  • Without using the “SIG” prefix. (e.g; -HUP)

For example, If you want to reload Nginx processes, you can run the command as below.

pkill -HUP nginx

The command pkill takes regular expressions as an argument in the command. You also need to specify the process names that you want to kill. It is advisable to use the pgrep command to display the matched processes first. After checking the processes, you can send signals to those processes. 

Let’s have an example of the same. If you want to send signals to the processes which contain “ssh” in their names use the command as below.

pkill '^ssh$'

If you want to match processes with the full argument, you can use -f option as below.

pkill -9 -f "ping 8.8.8.8"

Another option -u helps you to find out and kill the processes of specified users.

pkill -u localuser

In the above command, replace the word “localuser” with your system username. Alternatively, you can specify multiple usernames separated by commas.

pkill -u localuser, gnome, Linux

Conclusion on pkill command

As we already learned, the pkill command is useful to pass on the signals to find out the running programs in Linux. Using different pkill regular expressions, you can kill processes instantly. pkill also allows to find out processes by username. Additionally, you can kill/stop the selected process in Linux using the pkill command.

Filed Under: Commands Tagged With: linux, pkill command, terminal

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Linux Guides

  • Explain pkill command in Linux
  • Linux File Command, Explain with Syntax and Examples
  • Explain rm command in Linux with Examples
  • What is the /etc/shadow file in Linux
  • How to List Installed Packages on CentOS
  • How To Create a Sudo User in Ubuntu Linux

Read More On

  • CentOS
  • Commands
  • Ubuntu

What is Linuxtor?

Linuxtor.com is your education source to learn more about Linux, Shopify, DevOps and MEAN/MERN Stack development. We are a team of enthuasist pertaining to provide maximum possible guidance on or related to the Linux platform.

Explore about us

  • About Us
  • Contact us
  • Disclaimer
  • Privacy Policy

Copyright © 2023 All Rights Reserved Log in