Introduction
In Linux system administration, managing processes is a daily task. Sometimes it is necessary to stop, restart, or send a specific signal to a group of processes that share the same name. The pkill command allows doing this quickly and safely, avoiding having to manually search for the PID.
What is pkill?
pkill belongs to the procps package and works as a user-friendly interface to kill. Instead of specifying the process number (PID), a pattern is indicated that matches the executable name or other attributes such as user, terminal, or group. Internally, pkill uses pgrep to locate the PIDs and then sends the indicated signal.
Basic Syntax
The simplest form is:
pkill [options] <signal> <pattern>
If the signal is omitted, SIGTERM (15) is sent by default. Some useful options are:
-u user: filter by owner.-t tty: filter by terminal.-n: selects the most recent matching process.-o: selects the oldest process.-v: inverts the match (excludes the pattern).-f: matches the full command line, not just the executable name.
Common Signals
Signals can be indicated by number or by name. The most used ones in pkill are:
SIGTERM(15): requests orderly termination.SIGKILL(9): terminates the process immediately, with no possibility of being caught.SIGHUP(1): often used to reload daemon configurations.SIGINT(2): simulates pressing Ctrl+C.SIGSTOP(19): stops the process; it can be continued withSIGCONT.
Practical Examples
-
- Terminate all processes named
firefox:
- Terminate all processes named
pkill firefox
-
- Send
SIGHUPto thesshdThis post is also available in ESPAÑOL.
- Send