
kill Command in Linux
The kill command in Linux allows you to send signals to processes, telling them to take certain actions, most often to stop running. Despite its serious name, the kill command is very flexible and can be used for many purposes beyond just stopping processes.
Whether you're managing systems or just a casual user, knowing how to use the kill command effectively helps you keep control over your system's processes and ensures smooth operation.
Table of Contents
Here is a comprehensive guide to the options available with the kill command â
- Syntax of kill Command
- kill Command Options
- Common Signals of kill Command
- Examples of kill Command in Linux
Syntax of kill Command
The fundamental structure of the kill command is simple and easy to understand −
kill [OPTIONS]
Where −
-
stands for the Process ID of the target process. The kill command sends signals to the process identified by its PID. If no signal is specified, it defaults to sending the SIGTERM (terminate) signal. - [OPTIONS] represents various flags used with the command to modify its functionality.
kill Command Options
The kill command supports various options and signals, each serving a specific purpose. Here are some of the most commonly used options −
Option | Description |
---|---|
-l | Lists all available signals. |
-s |
Specifies the signal to be sent. |
-L, --table | Displays signal names and their corresponding numbers in a table format. |
-q |
Sends a real-time signal with the specified value. |
Common Signals of kill Command
Here are some of the most frequently used signals with the kill command −
- SIGTERM (15) − Gracefully asks a process to terminate. This is the default signal.
- SIGKILL (9) − Forces a process to terminate immediately. This cannot be ignored by the process.
- SIGHUP (1) − Sent to a process when its controlling terminal is closed; often used to reload configuration files.
- SIGINT (2) − Interrupts a process, similar to pressing Ctrl+C in the terminal.
- SIGSTOP (19) − Stops a process without terminating it, similar to pressing Ctrl+Z.
Examples of kill Command in Linux
Let's explore a few practical examples of the command kill on Linux environment −
- Graceful Termination with Default Signal (SIGTERM)
- Forced Termination with SIGKILL
- Listing Signals
- Reloading Configuration Files with SIGHUP
- Sending Signals to Process Groups
Graceful Termination with Default Signal (SIGTERM)
When you want to politely ask a process to terminate, you can use the default SIGTERM signal. This signal allows the process to perform cleanup operations before exiting.
kill 1615
By running this command, you send the default SIGTERM signal to this process. The process then gets a chance to close files, release resources, and perform any other necessary cleanup tasks before shutting down.

Note − In case of an "Operation not permitted" error, use sudo with the kill command.
Forced Termination with SIGKILL
In some cases, a process might not respond to the SIGTERM signal, either because it's stuck or ignoring the signal. In such scenarios, you can use the SIGKILL signal to forcefully terminate the process.
kill -9
For instance, if the process with PID 1489 is not responding to SIGTERM, you can force it to terminate immediately by using kill -9 1489.

The SIGKILL signal cannot be caught or ignored by the process, ensuring that it stops immediately. However, be cautious when using SIGKILL as it doesn't allow the process to clean up, which might lead to data corruption or other issues.
Listing Signals
If you want to see all the signals you can send using the kill command, you can use the -l option. This displays a list of signal names along with their corresponding numbers −
kill -l
Running kill -l in the terminal will produce a list of all available signals. This is particularly useful when you want to send a specific signal but are unsure of its name or number.

Reloading Configuration Files with SIGHUP
The SIGHUP signal is often used to instruct a process to reload its configuration files without terminating. This is useful for processes that need to apply new settings without restarting −
kill -1
Assume you have a process with PID 1487 that needs to reload its configuration. By executing kill -1 1487, you send the SIGHUP signal to the process. The process then reads its configuration files again and applies any changes, all without shutting down.

Sending Signals to Process Groups
You can send signals to entire process groups by prefixing the PID with a minus sign. This is useful when you want to target all processes in a group simultaneously.
kill --
If you have a process group with PGID 588 and you want to terminate all processes in the group, you can use kill -SIGTERM -588. This sends the SIGTERM signal to the process group identified by 1234, requesting all processes within the group to terminate gracefully.

Conclusion
The kill command is a fundamental tool for managing processes in Linux. It offers a range of options and signals that allow users to control processes effectively. Whether you are terminating unresponsive applications or reloading configuration files, mastering the kill command is essential for maintaining a well-managed Linux system.
By understanding its syntax, options, and practical applications, you can leverage the full power of the kill command. Remember to use signals wisely and ensure that you are targeting the correct processes to avoid accidental terminations of critical system services.