Linux kill Command
last modified March 3, 2025
The kill command in Linux is used to terminate processes by sending
specific signals. It is a powerful tool for managing running processes and
ensuring system stability. This tutorial covers basic and advanced usage of
kill with practical examples.
kill is commonly used to stop misbehaving processes, free up system
resources, or gracefully shut down applications.
Terminate a Process by PID
This example demonstrates how to terminate a process using its Process ID (PID).
kill 1234
The kill command sends the default SIGTERM signal to
the process with PID 1234, requesting it to terminate gracefully.
Forcefully Terminate a Process
This example shows how to forcefully terminate a process using the
SIGKILL signal.
kill -9 1234
The -9 option sends the SIGKILL signal, which
immediately terminates the process with PID 1234.
List All Available Signals
This example demonstrates how to list all available signals that can be sent
using the kill command.
kill -l
The -l option lists all signal names and their corresponding
numbers.
Send a Specific Signal
This example shows how to send a specific signal to a process.
kill -SIGHUP 1234
The -SIGHUP option sends the SIGHUP signal to the
process with PID 1234, often used to reload configurations.
Terminate Multiple Processes
This example demonstrates how to terminate multiple processes at once.
kill 1234 5678 91011
The kill command sends the SIGTERM signal to all
specified PIDs, requesting them to terminate gracefully.
Terminate Processes by Name
This example shows how to terminate processes by their name using
pkill.
pkill process_name
The pkill command sends the SIGTERM signal to all
processes matching process_name.
Gracefully Stop All Processes by User
This example demonstrates how to gracefully stop all processes owned by a specific user.
pkill -u username
The -u option sends the SIGTERM signal to all
processes owned by username.
Advanced: Terminate Processes with a Custom Signal
This example shows how to send a custom signal to a process.
kill -SIGUSR1 1234
The -SIGUSR1 option sends the SIGUSR1 signal to the
process with PID 1234, often used for custom process handling.
Best Practices for kill
- Use SIGTERM First: Always try
SIGTERMbeforeSIGKILLto allow graceful termination. - Check Process Status: Use
psortopto verify processes before terminating them. - Use pkill for Convenience: Use
pkillto terminate processes by name instead of PID. - Be Cautious with SIGKILL: Use
SIGKILLonly when necessary, as it does not allow cleanup.
Source
In this article, we have explored various examples of using the kill
command for terminating processes, including advanced features like custom
signals and process management by name or user.
Author
List all Linux tutorials.