kill
Command Cheatsheet
The kill
command in Unix-like systems is used to terminate processes by sending signals to them. It allows users to manage and control processes running on the system. Here’s a quick reference guide:
Basic Syntax
kill [OPTIONS] PID...
Common Signals
-1
,SIGHUP
: Hangup signal. Typically used to instruct a process to reload its configuration.-2
,SIGINT
: Interrupt signal. This is typically generated by pressing Ctrl+C and is used to terminate a process gracefully.-9
,SIGKILL
: Kill signal. Forces termination of a process. It cannot be caught or ignored by the process.-15
,SIGTERM
: Termination signal. This is a general-purpose signal to terminate a process gracefully.
Examples
Terminate a process by PID (default signal is
SIGTERM
):kill 1234
Send a specific signal to a process (e.g.,
SIGKILL
):kill -9 1234
Send a
SIGHUP
signal to reload a process (e.g., a daemon):kill -1 1234
Terminate multiple processes by PIDs:
kill 1234 5678 9101
Send a
SIGINT
signal to terminate a process gracefully (e.g., Ctrl+C):kill -2 1234
Additional Options
-l
,--list
: List available signals. Use withkill -l
.kill -l
-s SIGNAL
,--signal=SIGNAL
: Specify a signal by name or number.kill -s SIGTERM 1234
-p
,--pid PID
: Specify the process ID.kill -9 --pid 1234
Tips
Graceful Termination: Use
SIGTERM
(-15
) for normal termination as it allows the process to clean up resources.Forceful Termination: If a process does not respond to
SIGTERM
, useSIGKILL
(-9
) to force termination, but this can leave resources in an inconsistent state.
Additional Information
Help option:
kill --help
View manual page for
kill
:man kill
The kill
command provides essential functionality for managing processes in Unix-like systems, allowing users to terminate processes gracefully or forcefully depending on the situation. For more detailed information and advanced usage, refer to the man
page or use kill --help
.