Processes and tasks

Command pkill

Send a signal to processes using a template

Linux · Bash examples · commands run on the selected server

When to use pkill

Use pkill only after reviewing the same selection with pgrep. It sends signals to every matching process, so narrow the account and use exact matching when that is the intended scope.

Syntax

pkill [OPTIONS] TEMPLATE

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-x
Exact name match.
-u NAME
Limit the effective user.
-TERM
Select the standard termination signal.

Usage examples

Check for matches first

pgrep -a -u "$USER" -x sleep

The target process names and current-user restriction are checked without sending a signal.

Terminate only your own sleep test processes

pkill -TERM -u "$USER" -x sleep

Every exact-name sleep process owned by the current user receives a graceful termination signal.

Show help

pkill --help

Usage information is displayed for the installed implementation.

Notes and limitations

  • pkill signals all matching processes. Inspect the same filter with pgrep before using it.
  • A broad -f pattern can match unintended commands and shells.

Common questions and troubleshooting

Can I preview what pkill will affect?

Use pgrep with equivalent selection conditions and review the results. Processes may still change between inspection and signalling.

Why did more than one task stop?

All matches are signalled, not only the first. Use a verified individual PID when a single task should be affected.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man pkill.