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
- Process termination
- Process control
- Application restart
- Debugging
- 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
Graceful termination:
kill -15 pid
Force termination:
kill -SIGKILL pid
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
- Use SIGTERM first
- SIGKILL as last resort
- Verify process ID
- Check permissions
- Monitor process state
Safety Considerations
- Avoid killing system processes
- Check process ownership
- Consider dependencies
- Backup before killing
- Document actions