kill

Overview

The kill command sends signals to processes. It’s primarily used to terminate processes but can send any specified signal to a process.

Syntax

kill [options] pid...

Common Options

Option Description
-l List all signals
-s signal Specify signal to send
-SIGTERM Terminate process (default)
-SIGKILL Force kill process
-SIGHUP Hangup signal
-SIGINT Interrupt signal
-SIGSTOP Stop process
-SIGCONT Continue process
-0 Check process existence

Common Signals

Signal Number Description
SIGHUP 1 Hangup
SIGINT 2 Interrupt (Ctrl+C)
SIGQUIT 3 Quit
SIGKILL 9 Force kill
SIGTERM 15 Terminate (default)
SIGSTOP 19 Stop
SIGCONT 18 Continue
SIGUSR1 10 User defined 1
SIGUSR2 12 User defined 2

Key Use Cases

  1. Process termination
  2. Process control
  3. Application restart
  4. Debugging
  5. Service management

Examples with Explanations

Example 1: Terminate Process

kill 1234

Send SIGTERM to process 1234

Example 2: Force Kill

kill -9 1234

Force kill process 1234

Example 3: List Signals

kill -l

List all available signals

Understanding Output

  • No output on success
  • Error messages for:
    • No such process
    • Permission denied
    • Invalid signal
    • Operation not permitted

Common Usage Patterns

  1. Graceful termination:

    kill -15 pid
  2. Force termination:

    kill -SIGKILL pid
  3. Process group:

    kill -TERM -pid

Performance Analysis

  • Signal delivery time
  • Process state impact
  • System resource cleanup
  • Child process handling
  • Signal queue management

Additional Resources

Best Practices

  1. Use SIGTERM first
  2. SIGKILL as last resort
  3. Verify process ID
  4. Check permissions
  5. Monitor process state

Safety Considerations

  1. Avoid killing system processes
  2. Check process ownership
  3. Consider dependencies
  4. Backup before killing
  5. Document actions