Home > Process Management > pkill

pkill: Terminate/Signal Processes by Name

pkill is a command that sends signals to processes based on their name or other attributes. It is similar to `pgrep`, but it directly sends signals to the found processes. It is useful for terminating or restarting all processes with a specific name at once.

Overview

pkill uses the same pattern matching capabilities as `pgrep` to find processes, but it sends the specified signal to the found processes. The default signal is SIGTERM (15), which requests a graceful termination of the process. You can send SIGKILL with the `-9` option, but use this with caution as it is a forceful termination.

Key Features

  • Send signals to processes by name
  • Filter by various criteria such as user, terminal, full path
  • Default signal is SIGTERM (graceful termination)
  • Supports forceful termination (SIGKILL)

Key Options

The pkill command offers various options to precisely select the processes to which signals will be sent.

Signals and Matching

Process Filtering

Generated command:

Try combining the commands.

Description:

`pkill` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Demonstrates various ways to use pkill to terminate or send signals to specific processes.

Gracefully Terminate nginx Processes

pkill nginx

Sends a SIGTERM signal to all processes named nginx, requesting a graceful termination.

Forcefully Terminate firefox Processes Owned by a Specific User

pkill -u john -9 firefox

Forcefully terminates firefox processes running under a specific user (e.g., 'john').

Terminate All Processes Containing 'my_script.sh' in the Full Command Line

pkill -f my_script.sh

Terminates all processes whose full command line, not just the process name, includes 'my_script.sh'.

Terminate All Processes Running on a Specific Terminal (tty1)

pkill -t tty1

Sends a SIGTERM signal to all processes running on the tty1 terminal.

Send HUP Signal to httpd Processes (Restart)

pkill -HUP httpd

Sends a SIGHUP signal to httpd processes, requesting them to reload their configuration files or restart.

Tips & Precautions

Points to note and useful tips when using pkill.

Precautions

  • Use `pkill -9` (SIGKILL) as a last resort. It does not give processes a chance to perform cleanup tasks, which can lead to data corruption or system instability.
  • To prevent unintended process termination, it is recommended to first check which processes will be selected using `pgrep`. (e.g., `pgrep -l <pattern>`)
  • You can use regular expressions to specify patterns. (e.g., `pkill 'apache.*'`)
  • By default, pkill targets only processes of the current user. You need root privileges to terminate processes of other users.

Same category commands