DEV Community

Cover image for What is pkill?
Sparky-code
Sparky-code

Posted on

What is pkill?

The pkill command is a command-line utility that is used to terminate processes on Unix or Linux systems. It is an extremely powerful and efficient tool for system administrators and users alike.

It allows them to quickly and easily terminate processes by name, ID, or attribute, send different signals to processes, and search for processes based on their attributes. A must-have tool for system administration and working with Unix or Linux systems.

One of the most common uses of the pkill command is to terminate processes by name. Enter the command + the name of the process to terminate. For example, if you want to terminate a process named ‘firefox’, you would enter

pkill firefox

You can also use wildcards to match processes with similar names. E.g. For all processes with names starting with “chrome”.

pkill -f "chrome*"

The ‘pkill’ command also allows you to send different signals to processes, including SIGTERM (default), SIGKILL, or SIGINT. The SIGTERM signal requests that the process terminate gracefully, while the SIGKILL and SIGINT signals force the process to terminate immediately.

You can search for processes based on attributes. Search for processes running as a particular user, by specifying the user's name as a parameter.

pkill -U username

You can terminate processes based on their CPU usage. E.g. To terminate the process owned by the specified user that has the highest CPU usage.

pkill -u username -o %cpu -n 1

`-u` specifies the username of the user whose processes you want to terminate.
`-o %cpu` orders the processes by their CPU usage, with the highest usage first.
`-n 1` specifies that only the process with the highest CPU usage should be terminated. The '-n' flag takes a numerical value for how many processes should be terminated. In this case, only the process with the highest CPU usage (i.e., the one with the rank of '1') will be terminated.
Enter fullscreen mode Exit fullscreen mode

For more details on signals and defaults: Check this out

Top comments (1)

Collapse
 
femolacaster profile image
femolacaster

Great one. :)