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 ip Command: Inspect and Configure Network Interfaces and Routes

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Learn how to inspect and Configure Network Interfaces and Routes with the Linux ip command, including practical examples, key options, and important precautions.

Linux bunzip2 Command: Decompress bzip2 Files

Linux bunzip2 Command: Decompress bzip2 Files

Learn how to decompress bzip2 Files with the Linux bunzip2 command, including practical examples, key options, and important precautions.

How to Check the Linux Distribution, Version, Kernel, and Architecture

How to Check the Linux Distribution, Version, Kernel, and Architecture

Learn how to identify a Linux distribution and version with /etc/os-release, then check the running kernel and CPU architecture with hostnamectl and uname. The guide also covers scripts, legacy systems, containers, WSL, and chroot environments.

Linux which Command: Find Executables in PATH

Linux which Command: Find Executables in PATH

Learn how Linux which searches PATH for executables, shows all matching paths, differs from type and command -v, and should be used carefully in scripts.

Linux apt-get Command: Run APT Package Operations in Scripts

Linux apt-get Command: Run APT Package Operations in Scripts

Learn how to run APT Package Operations in Scripts with the Linux apt-get command, including practical examples, key options, and important precautions.

Linux wget Command: Download Files from URLs

Linux wget Command: Download Files from URLs

Learn how to download Files from URLs with the Linux wget command, including practical examples, key options, and important precautions.

Linux ps Command: Inspect Running Processes

Linux ps Command: Inspect Running Processes

Learn how to inspect Running Processes with the Linux ps command, including practical examples, key options, and important precautions.

Linux help Command: Read Help for Bash Built-in Commands

Linux help Command: Read Help for Bash Built-in Commands

Learn how to use the Linux help command to read usage information for Bash built-in commands, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux modinfo Command: Inspect Kernel Module Details

Linux modinfo Command: Inspect Kernel Module Details

Learn how to inspect Kernel Module Details with the Linux modinfo command, including practical examples, key options, and important precautions.

Linux xargs Command: Pass Standard Input as Command Arguments

Linux xargs Command: Pass Standard Input as Command Arguments

Learn how to pass Standard Input as Command Arguments with the Linux xargs command, including practical examples, key options, and important precautions.