$linuxjunkies
>

pkill(1)

Send signals to processes by name or other attributes instead of by process ID.

UbuntuDebianFedoraArch

Synopsis

pkill [OPTION]... PATTERN

Description

pkill sends a signal (default: SIGTERM) to all processes matching the given criteria. It's a convenient alternative to ps + grep + kill when you want to target processes by name, user, or other attributes without knowing their exact PID.

The PATTERN argument is treated as an extended regular expression by default. pkill matches against the process name (the command name as shown in ps output), but can also match against full command lines, usernames, and other process attributes using various options.

Related command pgrep displays matching process IDs instead of signaling them, useful for seeing what would be affected before running pkill.

Common options

FlagWhat it does
-signalSpecify signal to send (SIGTERM by default); use number (9, 15) or name (KILL, TERM)
-fMatch against full command line instead of just process name
-u USERNAMEOnly match processes owned by the specified user
-U USERNAMEOnly match processes with real UID of specified user
-g PGIDOnly match processes in the specified process group ID
-P PIDOnly match processes with specified parent process ID
-lList matching process names and IDs instead of sending signal
-aDisplay full command line of matching processes with -l
-xRequire exact match of process name (whole word only)
-nSelect only the newest matching process
-oSelect only the oldest matching process
-cCount matching processes; useful to verify before killing

Examples

Forcefully kill all Firefox processes (SIGKILL signal)

pkill -9 firefox

Terminate all sshd processes owned by user 'john'

pkill -u john sshd

List all Python processes matching 'myapp' in their command line

pkill -l 'python.*myapp'

Kill Node.js processes running server.js by matching full command

pkill -f 'node.*server.js'

Count how many nginx processes would be matched (useful verification)

pkill -c nginx

Kill only the newest Java process, leaving others running

pkill -n java

Pause (SIGSTOP) all child processes of PID 1234

pkill -SIGSTOP -P 1234

Kill apache2 processes owned by 'nobody' user with exact name match

pkill -x -u nobody apache2

Related commands