Problem Statement
What is the difference between kill, killall, and pkill commands?
Explanation
Kill sends signals to processes specified by PID. Basic syntax is kill PID or kill -SIGNAL PID. Without specifying a signal, it sends SIGTERM (15) for graceful termination. Use kill -9 PID (SIGKILL) for forceful termination when processes don't respond to SIGTERM. You must know the exact PID to use kill.
Killall terminates all processes matching a given process name. Syntax: killall processname kills all processes named processname. It's more convenient than kill when multiple instances are running, like killall firefox kills all Firefox processes. Use -u option to kill processes for specific user: killall -u username processname.
Pkill uses pattern matching and additional criteria like user, terminal, or command pattern. Syntax: pkill pattern kills processes matching the pattern. Example: pkill -u username firefox kills Firefox processes for specific user. Pkill is most flexible, allowing combinations like pkill -t pts/0 to kill processes on specific terminal. Understanding these tools helps manage processes efficiently in different scenarios.
Practice Sets
This question appears in the following practice sets:
