Linux pkill Command: Signal Processes by Name

pkill sends a signal to processes that match a name or condition. The default is SIGTERM, which requests termination, but if the name matches broadly, it can affect multiple unintended processes.

What is the pkill command?

It uses selection criteria like pgrep, but instead of displaying the results, it sends a signal to the target. Therefore, it is safe to first run pgrep -a with the same criteria to verify the target user and command line.

Basic syntax

pkill [option] pattern

The installed implementation and options may vary depending on the distribution. Check the current system description with man pkill.

Examples

First, verify the target

Review whether the process name matches exactly.

pgrep -a -x myworker

Default termination request

Send SIGTERM to processes that match the reviewed name.

pkill -x myworker

Limit scope by user

If processes with the same name are running under multiple accounts, specify the user together.

pkill -u alice -x myworker

Checking the Result of a Termination Command

pkill sends a signal to processes matching a name pattern. Even if it succeeds, it usually does not print a list of PIDs, so first run pgrep with the same criteria to verify the target.

pgrep -a -x demo-worker
pkill -TERM -x demo-worker
pgrep -a -x demo-worker

The initial query may show test processes, sending the signal itself produces no output, and the final query will be empty if termination is complete. Sending a signal does not guarantee an immediate termination, so check again after a short while.

-x restricts the match to the full name. Be especially careful when using -f to search the entire command line, as the pattern may match more widely. Apply the examples only to the test processes you created and follow operational procedures for actual services.

Main Options and Format

Options/Format Description
-x Select processes that exactly match the full name.
-u user Limit the target to valid user IDs.
-f Check the entire command line as the target.
-TERM Explicitly send SIGTERM.
-e Display information about the target to which the signal was sent in supported implementations.

Precautions when using

pkill -f can select multiple tasks if only part of the command line matches. When managing services, prioritize the normal shutdown procedure of service management tools whenever possible. SIGKILL skips cleanup tasks, so it is not usually used as the first choice.

Frequently Asked Questions

What is the difference between pkill and pgrep?

pgrep finds PIDs that match the criteria, while pkill actually sends signals to processes that match the criteria.

Official Documentation

You can check the exact behavior of the options and differences depending on the implementation in the official documentation related to pkill.

More in This Category
Linux alias Command: Create Command Shortcuts

Linux alias Command: Create Command Shortcuts

Learn how to use the Linux alias command to create, inspect, and make shell command aliases persistent, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux scp Command: Copy Files over SSH

Linux scp Command: Copy Files over SSH

Learn how to copy Files over SSH with the Linux scp command, including practical examples, key options, and important precautions.

Linux touch Command: Create Files and Change Timestamps

Linux touch Command: Create Files and Change Timestamps

Learn how to use the Linux touch command to create empty files and change access or modification timestamps, including reference times, date formats, and symlink handling.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux tmux Command: Detach and Reattach Terminal Sessions

Linux tmux Command: Detach and Reattach Terminal Sessions

Learn how to detach and Reattach Terminal Sessions with the Linux tmux command, including practical examples, key options, and important precautions.

Linux nslookup Command: Query DNS Names and Records

Linux nslookup Command: Query DNS Names and Records

Learn how to query DNS Names and Records with the Linux nslookup command, including practical examples, key options, and important precautions.

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Linux Tutorial / Navigate Directories with pwd, ls, cd, and tree

Use pwd, ls, cd, and tree to find your current location, inspect directories, navigate paths, and check where each command takes you.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.

Linux xz Command: Compress a File in xz Format

Linux xz Command: Compress a File in xz Format

Learn how to compress a File in xz Format with the Linux xz command, including practical examples, key options, and important precautions.

Linux csplit Command: Split Files at Lines or Patterns

Linux csplit Command: Split Files at Lines or Patterns

Learn how to split Files at Lines or Patterns with the Linux csplit command, including practical examples, key options, and important precautions.