Understanding the kill Command

Basic Usage of kill

The kill command is used to send signals to processes, typically to terminate them. While the most common signal is SIGTERM (signal number 15), which requests a graceful shutdown, kill can send various signals to control process behavior.

kill [OPTIONS]

Options Available with kill

-l (List Signals)

List all available signal names:

kill -l

-s (Specify Signal)

Specify the signal to send by name or number:

kill -s SIGKILL

-n (Numeric Signal)

Send a signal using its number:

kill -n 9

This sends the SIGKILL signal (9) to the specified process.

-p (Process ID)

Only print the process ID without sending a signal:

kill -p

Commonly Used Signals

Signal Description
SIGTERM (15) Request termination of a process (default signal).
SIGKILL (9) Force termination of a process (cannot be caught or ignored).
SIGHUP (1) Hang up signal, often used to reload configurations.
SIGINT (2) Interrupt signal, usually sent by pressing Ctrl + C.
SIGQUIT (3) Quit signal, often produces a core dump.

Examples of kill Command

Terminate a Process Gracefully

kill 1234

This sends the SIGTERM signal to process ID 1234.

Force Terminate a Process

kill -9 1234

This sends the SIGKILL signal to process ID 1234.

List Available Signals

kill -l

This displays a list of all available signals.

Summary of Options

Option Description
-l List all available signal names.
-s Specify the signal to send by name or number.
-n Send a signal using its number.
-p Only print the process ID without sending a signal.