Terminate Processes
On this page
Kill Command
It’s actually a tool for sending signals to processes, not necessarily killing them.
Default Signal
The default signal for the kill
command is SIGTERM
, corresponding to number 15
, for a graceful termination.
Available Signals
Specify Signal Type
Multiple Processes
Special Process Number
The process number -1
represents all processes, and the following command will terminate all processes that you (the current user) can terminate.
Danger
Do not execute in the root user
If I want to execute as the kuga
user, I can first view the processes of that user as the root
user.
Then, execute the command kill -9 -1
in the kuga terminal.
This will immediately disconnect, and viewing the kuga
user processes on root
will find that they are all gone.
Pkill Command
It sends signals to processes based on their names.
Default Signal
The default signal for the pkill
command is SIGTERM
, corresponding to number 15
, for a graceful termination.
Specify Signal Type
Specify User Processes
Precision Process Name
Pgrep
It looks up process IDs based on process names.
Ignore Case
Specify User Processes
Process IDs and Names
Without -l
, it will only display the process ID.
Number of Matching Processes
Specify Parent PID
Recently Started Processes
Earliest Started Processes
Precision Process Name
Common Signals
SIGTERM - 15
Requests the process to terminate. This signal is “friendly” and allows the process to perform cleanup before exiting.
It is the default signal for kill
and pkill
commands.
Usually used for a graceful termination of processes, giving them time to handle unfinished tasks.
SIGKILL - 9
Forces the process to terminate. This signal cannot be caught, blocked, or ignored, and the process will be immediately terminated.
Sending SIGKILL
will directly stop the process without allowing it to perform any cleanup operations.
Used for processes that cannot be normally terminated, when SIGTERM
is ineffective.
SIGINT - 2
Interrupt signal, usually sent by the user through Ctrl+C
, used to interrupt foreground running processes.
Used for manually interrupting processes, especially interactive processes.
SIGQUIT - 3
Quit signal, usually sent by the user through Ctrl+\
, indicating that the process should generate a core dump and exit.
Used for debugging, when you want the process to generate a core dump for analysis.
SIGHUP - 1
Hangup signal, usually indicating that the terminal or console connection has been disconnected.
Many daemon processes will reload their configuration files when they receive the SIGHUP
signal.
Used for reloading the configuration of daemon processes or causing them to restart.