kill

process managementLinux/Unix
The kill command is one of the most frequently used commands in Linux/Unix-like operating systems. kill The kill command is used to send signals to processes, typically to terminate them. By default, it sends the TERM (terminate) signal, but it can send any specified signal to a process identified by its process ID (PID). The kill command is essential for process management and system administration tasks.

Quick Reference

Command Name:

kill

Category:

process management

Platform:

Linux/Unix

Basic Usage:

kill [options] [arguments]

Common Use Cases

  • 1

    Process termination

    Send signals to terminate processes

  • 2

    Resource management

    Manage system resources by terminating processes

  • 3

    Scripting

    Use in shell scripts to terminate processes programmatically

  • 4

    Troubleshooting

    Resolve issues with unresponsive or misbehaving processes

Syntax

kill [options] PID...

Options

Option Description
-s, --signal SIGNAL Specify the signal to send (by name or number)
SIGNAL Signal number or name (can be specified without -s, e.g., kill -9 PID)
-l, --list [SIGNAL] List signal names, or convert a signal number to a name
-L, --table List signal names and numbers in a table
-h, --help Display help message and exit
-v, --version Output version information and exit

Examples

How to Use These Examples

The examples below show common ways to use the kill command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

#

Basic Usage:

kill 1234

Send the default TERM signal to process with PID 1234.

kill -9 1234

Send the KILL signal (9) to forcefully terminate a process with PID 1234.

kill -SIGTERM 1234

Send the TERM signal using the signal name instead of number.

Multiple Processes:

kill 1234 5678 9012

Send the default TERM signal to multiple processes at once.

kill -15 $(pgrep firefox)

Send the TERM signal (15) to all processes with "firefox" in their name.

Signal Types:

kill -l

List all available signal names and numbers.

kill -HUP 1234

Send the HUP (hangup) signal, often used to make a process reload its configuration.

kill -STOP 1234

Send the STOP signal to pause a process (can be resumed later).

kill -CONT 1234

Send the CONT signal to resume a previously stopped process.

Advanced Usage:

sudo kill -9 -1

Terminate all processes you have permission to terminate (use with extreme caution).

kill -0 1234

Check if a process exists without sending any signal (returns success if process exists).

kill -s USR1 1234

Send a user-defined signal (USR1) to a process, often used for custom application behavior.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Common Signals:

  • 1 (HUP): Hangup - Often used to reload configuration
  • 2 (INT): Interrupt - Same as pressing Ctrl+C
  • 3 (QUIT): Quit - Similar to SIGINT but produces a core dump
  • 9 (KILL): Kill - Forceful termination, cannot be caught or ignored
  • 15 (TERM): Terminate - Default signal, graceful termination
  • 18 (CONT): Continue - Resume a stopped process
  • 19 (STOP): Stop - Pause process, cannot be caught or ignored
  • 20 (TSTP): Terminal stop - Same as pressing Ctrl+Z

Signal Selection Guidelines:

  • Start with SIGTERM (15) for normal termination
  • Use SIGKILL (9) only when a process doesn't respond to SIGTERM
  • SIGHUP (1) is often used to make daemons reload their configuration
  • SIGSTOP (19) and SIGCONT (18) can be used to pause and resume processes
  • Application-specific signals: SIGUSR1 (10) and SIGUSR2 (12) for custom behaviors

Finding Process IDs:

  • Use ps to list processes and their PIDs
  • Use pgrep to find PIDs by process name
  • Use pidof to find PIDs of a named program
  • Use top or htop for an interactive view of processes
  • Check /proc filesystem for process information

Permissions:

  • You can only send signals to your own processes unless you have root privileges
  • Use sudo to kill processes owned by other users
  • Some critical system processes are protected from being killed
  • Even root cannot interrupt certain kernel operations

Process Groups and Sessions:

  • Send a signal to all processes in a process group by using negative PID
  • Use kill -TERM -1234 to send SIGTERM to all processes in group 1234
  • Special PID -1 refers to all processes the user has permission to terminate
  • Some shells implement built-in kill commands with additional features

Checking Signal Success:

  • The kill command returns success if the signal was sent, not if it had the desired effect
  • Use kill -0 PID to check if a process exists without sending a signal
  • Monitor process status with ps after sending signals
  • Check application logs for information about signal handling

Alternative Commands:

  • pkill - Kill processes by name, not PID
  • killall - Kill processes by exact name
  • xkill - Kill a process by clicking on its X11 window
  • Desktop environment task managers (GUI alternatives)

Safety Considerations:

  • Avoid using kill -9 as a first resort, as it doesn't allow programs to clean up
  • Be extremely cautious with kill -9 -1 as it attempts to kill all possible processes
  • Sending signals to critical system processes can cause system instability
  • Double-check the PID before sending signals, especially SIGKILL
  • Save your work before terminating application processes

Common Use Cases:

  • Terminating unresponsive applications
  • Reloading daemon configurations without restarting (using SIGHUP)
  • Managing background jobs in scripts
  • Implementing graceful shutdown procedures
  • Debugging and troubleshooting applications

Signal Handling in Applications:

  • Applications can catch and handle most signals
  • SIGKILL and SIGSTOP cannot be caught, blocked, or ignored
  • Well-designed applications perform cleanup when receiving SIGTERM
  • Custom signal handlers allow for application-specific behaviors

Related Commands:

  • ps - Display information about active processes
  • pgrep - Look up processes by name and other attributes
  • pkill - Send signals to processes based on name and other attributes
  • killall - Kill processes by name
  • top - Display and manage process activity
  • htop - Interactive process viewer
  • fuser - Identify processes using files or sockets
  • nice and renice - Run programs with modified scheduling priority

Tips & Tricks

1

Use the -s signal option to specify the signal to send

2

Use the -p pid option to specify a process ID

3

Use the -l option to list all signals

4

Use the -1 option to send a SIGKILL signal

5

Use the -9 option to send a SIGKILL signal

Common Use Cases

Process termination

Send signals to terminate processes

Resource management

Manage system resources by terminating processes

Scripting

Use in shell scripts to terminate processes programmatically

Troubleshooting

Resolve issues with unresponsive or misbehaving processes

Security

Prevent unauthorized access to system resources

Related Commands

These commands are frequently used alongside kill or serve similar purposes:

Use Cases

1

Process termination

Send signals to terminate processes

2

Resource management

Manage system resources by terminating processes

3

Scripting

Use in shell scripts to terminate processes programmatically

4

Troubleshooting

Resolve issues with unresponsive or misbehaving processes

5

Security

Prevent unauthorized access to system resources

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the kill command works in different scenarios.

$ kill
View All Commands