Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

pkill

Signal processes based on name and other attributes.

Description

Looks up processes based on name and other attributes, then sends a signal to each matching process. Uses the same matching logic as pgrep. By default, sends SIGTERM.

Inputs

  • /proc/[pid]/stat – process status (PID, comm, state, PPID, pgrp, session, tty, starttime)
  • /proc/[pid]/status – effective and real UID/GID
  • /proc/[pid]/cmdline – full command line (for -f matching)
  • /proc/uptime – system uptime (for --older calculations)
  • kill() syscall via rustix – sends signals to matched processes

Arguments

Pattern

ArgumentDescription
pattern (positional, optional)Extended regex to match against process names

Signal selection

FlagDescription
--signal SIGNALSignal to send, by name or number (default: TERM)

Output options

FlagDescription
-c, --countPrint count of matched processes instead of signaling
-e, --echoDisplay name and PID of each signaled process

Matching options

FlagDescription
-f, --fullMatch pattern against full command line, not just process name
-i, --ignore-caseCase-insensitive pattern matching
-x, --exactRequire exact match of the process name (not a substring)

Selection filters

FlagDescription
-n, --newestSelect only the most recently started matching process
-o, --oldestSelect only the earliest started matching process
-O, --older SECSSelect processes older than SECS seconds
-P, --parent PPID,...Match only processes whose parent PID is listed
-g, --pgroup PGRP,...Match only processes in the listed process groups
-G, --group GID,...Match only processes with the listed real group IDs
-s, --session SID,...Match only processes in the listed sessions
-t, --terminal TERM,...Match only processes on the listed controlling terminals
-u, --euid UID,...Match only processes with the listed effective user IDs or names
-U, --uid UID,...Match only processes with the listed real user IDs or names
-r, --runstates STATE,...Match only processes in the listed run states (R, S, D, Z, T, etc.)

Note: -v (inverse matching) is intentionally not supported in pkill, matching procps-ng behavior.

Behavior

pkill iterates over all processes in /proc, applies the same filtering and pattern matching logic as pgrep, then sends a signal to each matched process.

Signal parsing

The --signal value is resolved in the following order:

  1. Named signal without prefix: TERM, HUP, KILL, etc.
  2. Named signal with SIG prefix: SIGTERM, SIGHUP, SIGKILL, etc.
  3. Numeric signal: 15, 1, 9, etc.

Supported signal names: HUP, INT, QUIT, ILL, TRAP, ABRT (IOT), BUS, FPE, KILL, USR1, SEGV, USR2, PIPE, ALRM, TERM, STKFLT, CHLD (CLD), CONT, STOP, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF, WINCH, IO (POLL), PWR, SYS.

Process matching

The matching algorithm is shared with pgrep:

  • The invoking process (pkill itself) is always excluded from matches.
  • Without -f, the pattern is matched against the process comm name.
  • With -f, the pattern is matched against the full command line.
  • With -x, the pattern must match the entire name (anchored match).
  • Selection filters (parent, group, terminal, etc.) are combined with AND logic.
  • -n and -o are applied after all other filtering.

Echo mode (-e)

When --echo is specified, pkill prints a line for each successfully signaled process:

name killed (pid N)

Count mode (-c)

When --count is specified, pkill prints the number of matching processes instead of sending signals.

Exit codes

CodeMeaning
0At least one process was matched and successfully signaled
1No processes matched, or signaling failed for all matches
2Syntax error in command line arguments
3Fatal error