pkill linux command explained

Written by
Date: 2020-03-20 19:00:00 00:00


Overview

When you are working with Linux and want to kill a process the first step is to get the Process ID or PID which you can do by using top or htop, but you can also use pkill

pkill is like kill but uses search criteria to kill processes based on names, users or other criteria

Syntax

The command syntax is:

pkill [options] pattern

Everything that matches the pattern will receive a 15 (TERM) signal, unless other is specified. If you want to send another signal, you can use the signal option.

Examples

If you want to kill all firefox processes you can use this command

pkill firefox

This will kill the master and all child processes of firefox.

If you want to send some other signal like kill instead of gracefull kill, that is 9 instead of 15 do this:

pkill -9 firefox

There are some other usefull options:

pkill -u username

The above command will kill all processes initiated by the username username and logout the user.

pkill -i proccess-name

The above command will kill the process that matches the criteria and will ignore case.

pkill -f "complete command line"

The above command will kill the process that matches the full string so if you have several rsync commands running on different servers you can kill just one of the processes, be sure to use quotation marks.