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:
Press Ctrl + C to stop
Using the pkill command
This is its syntax:
pkill [option] 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
$ 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
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.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.