×


Use pkill Command in Linux System - An overview ?

pkill is a command-line utility that sends signals to the processes of a running program based on given criteria. The processes can be specified by their full or partial names, a user running the process, or other attributes.

The pkill command is a part of the procps (or procps-ng) package, which is pre-installed on nearly all Linux distributions. 

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.

In this context, we shall look into how to use the pkill command in Linux.


How to list running processes in Linux ?

You can list all running processes on your Ubuntu machine by running the following command:

$ top

To stop, simply Press Ctrl + C.


How to use the pkill command ?

The syntax for pkill command is:

$ pkill [option] pattern

Pattern here Invokes an extended regular expression that matches a process or command-line name.

If you use pkill command-line without [option], 15 (-TERM) signal will be sent by pkill to the PID. (Process ID).

Linux users usually use the three types of signals as below:

  • 1 (HUP): reload a process
  • -9 (KILL): kill a process
  • 15 (TERM): stop a process gracefully


For example:

$ pkill -9 chrome

The above command will close the chrome browser.

kill -l is used to list all the signals you can use.


There are 3 different ways to specify the signals:

  • using a number (e.g., -9)
  • with the "SIG" prefix (e.g., -SIGKILL)
  • without the "SIG" prefix (e.g., -KILL)


For demonstration, in order to kill the oldest created screen:

$ pkill -9 -o screen

To reload the gitlab-runner process, run:

$ sudo pkill -HUB gitlab-runner


[Need assistance in fixing Software Installation issues in Linux Systems? We can help you. ]


Conclusion

This article covers how to use the pkill command in Linux. pkill is basicity a wrapper around the pgrep program that only prints a list of matching processes.

The syntax for the pkill command is as follows:

$ pkill [OPTIONS] <PATTERN>

The matching <PATTERN> is specified using extended regular expressions.

For more information about pkill command, visit the pkill man page or type man pkill in your terminal.


Other Linux commands:

  • ps — Report the status of a process or processes.
  • killall — Kill processes by name.
  • kill — Send a signal to a process, affecting its behavior or killing it.