Introduction
In Linux system management, 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 commandpkillallows it to be done quickly and safely, avoiding having to search the PID manually.
What's pkill?
pkillbelongs to the packageprocpsand works as a friendly interface ofkill. Instead of specifying the process number (PID), a pattern that matches the executable name or other attributes such as the user, terminal or group is indicated. Internally,pkillusepgrepto locate the PID and then send the indicated signal.
Basic syntax
The simplest way is:
pkill [options]
If the signal is omitted, it is sent by defaultSIGTERM(15). Some useful options are:
-u usuario: filter per owner.-t tty: terminal filter.-n: select the most recent matching process.-o: select the oldest process.-v: reverse the coincidence (excludes the pattern).-f: matches the complete command line, not just the executable name.
Common signs
The signals can be indicated by number or by name. The most used inpkillare:
SIGTERM(15): request orderly completion.SIGKILL(9): the process is immediately completed, without the possibility of capture.SIGHUP(1): usually used to recharge daemon configurations.SIGINT(2): simulates theCtrl + C.SIGSTOP(19): stops the process; it can be continued withSIGCONT.
Practical examples
-
- Finish all called processes
firefox:
- Finish all called processes
pkill firefox
-
- Send
SIGHUPto thesshdof the useradmin:
- Send
pkill -u admin -HUP sshd
-
- Stop the most recent process that coincides with
backup.sh:
- Stop the most recent process that coincides with
pkill -n -f backup.sh
-
- Restart a service by sending
SIGUSR1to all processes whose name containsnginx:
- Restart a service by sending
pkill -USR1 nginx
Cautions and best practices
Althoughpkillis powerful, its careless use can affect the system. It is recommended that:
- First run
pgrepwith the same pattern to see which PID will be affected. - Avoid using comodines too wide as
pkill *; could try to kill critical processes. - In production environments, consider the use of
sudoonly when necessary and record the shares in a log. - Remember that
SIGKILLdoes not allow proper cleaning; use only whenSIGTERMIt didn't work.
Conclusion
The commandpkillsimplifies process signalling by name, saving time and reducing the possibility of errors when searching for PID manually. Knowing their syntax, the most common signals and applying good practices, any Linux administrator can manage processes efficiently and safely.


