Managing Processes (kill)
The kill command sends signals to processes, allowing you to stop, pause, or control running programs.
Basic Usage
kill PID
kill -9 PID
Understanding Signals
Signals are messages sent to processes:
| Signal | Number | Name | Effect |
|---|---|---|---|
| SIGTERM | 15 | Terminate | Graceful shutdown |
| SIGKILL | 9 | Kill | Forced shutdown |
| SIGHUP | 1 | Hangup | Restart/reload |
| SIGSTOP | 19 | Stop | Pause process |
| SIGCONT | 18 | Continue | Resume process |
Common kill Commands
kill PID # Graceful (SIGTERM)
kill -9 PID # Force kill (SIGKILL)
kill -HUP PID # Restart/reload
kill -STOP PID # Pause
kill -CONT PID # Resume
Finding the PID
Before killing, find the process ID:
ps aux | grep process_name
pgrep process_name
pidof program
Exercise: Find and Signal Process
View a process and understand how to send signals:
killall - Kill by Name
Kill processes by name instead of PID:
killall firefox
killall -9 chrome
killall -u username # All processes by user
pkill - Pattern-Based Kill
More flexible than killall:
pkill firefox # Match process name
pkill -f "python app" # Match full command
pkill -u www-data # By user
Graceful vs Force Kill
SIGTERM (default, signal 15)
- Allows cleanup
- Process can save data
- May be ignored
kill PID
kill -15 PID
kill -TERM PID
SIGKILL (signal 9)
- Cannot be ignored
- No cleanup opportunity
- Last resort
kill -9 PID
kill -KILL PID
Common Scenarios
Stop Unresponsive Program
# Try graceful first
kill PID
# If still running, force kill
kill -9 PID
Restart Service
kill -HUP $(pidof nginx)
# nginx reloads config
Kill All User Processes
pkill -u username
Kill Process on Port
kill $(lsof -t -i:8080)
Safety Tips
- Check before killing: Verify PID is correct
- Try graceful first: Use SIGTERM before SIGKILL
- Don't kill PID 1: That's init/systemd (system will crash)
- Be careful with killall: Make sure name is specific
Alternatives
On Modern Systems
systemctl stop service # Stop a service
systemctl restart service # Restart a service
GUI Method
Use your desktop's system monitor or task manager.
Related Commands
| Command | Purpose |
|---|---|
kill | Send signal to PID |
killall | Kill by exact name |
pkill | Kill by pattern |
xkill | Kill by clicking window |
htop | Interactive process manager |
Key Takeaways
kill PIDsends SIGTERM (graceful stop)kill -9 PIDforces immediate termination- Find PID first with
ps aux | greporpgrep - Always try graceful termination first
- Use
killallorpkillto kill by name
التالي · الدرس 32 من 40
Introduction to Package Managers
قراءة 2 دقيقة
أنهيت 31 من 40 درسًا

اسأل Byte عن هذا الدرس
محادثة خاصة حول هذا الدرس. قرأ Byte الدرس كاملًا، ويجيب خلال ثوانٍ، ويُظهر القسم الذي تأتي منه كل إجابة. يمكنك السؤال بأي لغة.
الأسئلة والأجوبة
أسئلة عامة حول هذا الدرس. يجيب AI Tutor فورًا بلغتك، ويراجع فريق FreeAcademy الإجابات، ويمكن لكل المتعلمين قراءتها.

