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 signals |
-s signal |
Specify signal |
-n signum |
Signal number |
-v |
Verbose mode |
-w |
Wait for death |
-0 |
Check existence |
-p |
Print PID |
-q |
Quiet mode |
-a |
All processes |
-u user |
User processes |
Common Signals
Signal | Number | Description |
---|---|---|
SIGHUP | 1 | Hangup |
SIGINT | 2 | Interrupt |
SIGQUIT | 3 | Quit |
SIGKILL | 9 | Kill |
SIGTERM | 15 | Terminate |
SIGSTOP | 19 | Stop |
SIGCONT | 18 | Continue |
SIGUSR1 | 10 | User defined 1 |
SIGUSR2 | 12 | User defined 2 |
SIGTSTP | 20 | Terminal stop |
Key Use Cases
- Process termination
- Process control
- Application restart
- Debugging
- System management
Examples with Explanations
Example 1: Basic Kill
kill 1234
Send SIGTERM
Example 2: Force Kill
kill -9 1234
Send SIGKILL
Example 3: List Signals
kill -l
Show available signals
Common Usage Patterns
Graceful stop:
kill -15 PID
Force stop:
kill -KILL PID
Check process:
kill -0 PID
Signal Handling
- Default action
- Ignore signal
- Catch signal
- Block signal
- Process groups
Additional Resources
Best Practices
- Use SIGTERM first
- Wait for exit
- Check status
- Document actions
- Verify results
Security Considerations
- Process ownership
- Signal permissions
- System impact
- Zombie processes
- Resource cleanup
Troubleshooting
- Process won’t die
- Permission denied
- Invalid PID
- Zombie processes
- Signal handling
Process States
- Running
- Sleeping
- Stopped
- Zombie
- Dead