CentOS Debian Mint openSUSE Red Hat Ubuntu

How to Use pkill Command

How to Use pkill Command

Introduction

pkill is a command line used to send terminated signals to processes. The signal can be sent to any process by invoking the full name or shortened name.

This article will describe the details of how to use the pkill command in Linux.

The running processes

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

$ top

Output:

Press Ctrl + C to stop

Using the pkill command

This is its syntax:

pkill [option] pattern

pattern

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.

Output:

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

Conclusion

You’ve already gone through the details of how to use the pkill command in Linux.

If you have any comments, please let me know. Thanks for reading.

Similar Posts