Files
oam/knowledge base/pkill.md

1.8 KiB

pkill

TODO

Command-line tools that sends signals to the processes of a running program based on given criteria.

  1. TL;DR
  2. Further readings
    1. Sources

TL;DR

Basically a wrapper around pgrep and kill.

Part of the procps (or procps-ng) package, which is pre-installed on nearly all Linux distributions.

The processes can be specified by:

  • Their full or partial name.
  • A user running the process.
  • Other attributes.

Returns 0 when at least one running process matched the requested pattern. Otherwise, its exit code is 1.

Setup
apt install 'procps'
brew install 'proctools'  # or brew install 'pkill'
dnf install 'procps-ng'
yum install 'procps-ng'
Usage
# Gracefully stop all processes of programs matching the given pattern
pkill 'pattern'
pkill -15 'pattern'
pkill -TERM 'pattern'
pkill -SIGTERM 'pattern'
pkill --signal 'TERM' 'pattern'

# Display what processes are sent signals
pkill -e …
pkill --echo …

# Only kill processes of specific users' *real* id
pkill -u 'mark' …
pkill --uid 'mark,john'
Real world use cases
pkill -HUP 'nginx'
pkill --signal 'TERM' --exact 'yes'
pkill '^ssh$'
pkill -9 -f "ping 8.8.8.8"
pkill -KILL -u 'mike' 'gdm'

Further readings

Sources