HxHippy

pkill

Signal processes based on name and other attributes

Overview

pkill sends signals to processes based on their name and other attributes, such as user ID or full command line. By default, it sends the SIGTERM signal.

Syntax

pkill [OPTION]... PATTERN

Common Options

-signal, --signal signal

Specify the signal to send (name or number, e.g., -9 or -KILL). Defaults to SIGTERM.

-f, --full

The pattern is normally only matched against the process name. When -f is set, the full command line is used.

-x, --exact

Only match processes whose name (or command line if -f is used) is exactly the pattern.

-u euid, --euid euid

Only match processes whose effective user ID is euid.

-U uid, --uid uid

Only match processes whose real user ID is uid.

-G gid, --Ggid gid

Only match processes whose real group ID is gid.

--older-than seconds

Match only processes older than the specified time in seconds.

--newer-than seconds

Match only processes newer than the specified time in seconds.

-c, --count

Count the number of matching processes and display the count instead of killing them.

-l, --list-name

List the name of the process along with the PID (does not kill).

-n, --newest

Select only the newest of the matching processes to signal.

-o, --oldest

Select only the oldest of the matching processes to signal.

-i, --ignore-case

Ignore case distinctions in pattern.

Examples

$ pkill firefox

Sends SIGTERM to all processes named firefox.

$ pkill -9 -f "defunct_script.sh"

Sends SIGKILL to all processes whose full command line contains defunct_script.sh.

$ pkill -u username java

Sends SIGTERM to all java processes owned by username.

$ pkill -x very_specific_daemon

Sends SIGTERM only to processes exactly named very_specific_daemon.

$ pkill -f -i "my application"

Sends SIGTERM to processes whose command line contains "my application", ignoring case.

$ pkill -o -f "backup_job"

Sends SIGTERM to the oldest running process whose command line matches "backup_job".

$ pkill -c defunct

Counts the number of processes named "defunct" without sending a signal.

$ pkill -i -n "my_process"

Sends SIGTERM to the newest process whose name matches "my_process", ignoring case.

processsignalterminatekillnamepatternpkillpgrep