Linux Process Management
Monitor, Control & Optimize Servers Like a Senior DevOps Architect
Linux Process Management
Monitor, Control & Optimize Servers Like a Senior DevOps Architect
1. Introduction (ELI5 Mode)
DevOps me kyun? Agar server slow hai, toh aapko pata hona chahiye kaunsa process CPU kha raha hai aur use kaise handle karna hai.
2. Core Concepts
A. PID (Process ID)
Yeh har process ka Aadhaar Card number hai. Bina PID ke aap kisi process ko touch nahi kar sakte.
B. Foreground vs Background
- Foreground: Jo aapke screen par chal raha hai (Terminal block hai).
- Background: Jo piche khamoshi se chal raha hai (Terminal free hai).
3. The DevOps Toolbox (Commands) 🛠️
Monitor Live Resources (The Dashboard):
# Real DevOps me ‘top’ se zyada ‘htop’ use hota hai kyunki ye colorful aur intuitive hai.
List Specific Processes:
# Nginx ki sari processes ko list karne ke liye.
Forcefully Stop a Process:
4. 15 Real-World DevOps Scenarios 🔥
1. Killing Stuck Process
kill -9 4567
Ziddi process jo hang ho gaya ho.
2. Check CPU Consumption
top -o %CPU
Pata karo kaunsa process server par bojh hai.
3. Run Backup in Background
./backup.sh &
Script piche chalti rahegi, aap kaam karte raho.
4. Restart Crashed Nginx
sudo systemctl restart nginx
Production server par website wapas zinda karna.
5. Monitor Service Status
systemctl status docker
Check karo Docker active hai ya dead.
6. Find Process by Name
pgrep -l python
Sari python scripts ki PID ek sath dekhna.
7. Lowering Priority (Nice)
nice -n 10 ./script.sh
Script ko kam CPU priority dena.
8. Real-time Memory Check
watch -n 1 free -m
Har second RAM usage update dekhna.
9. Bringing BG to FG
fg %1
Background job ko wapas screen par lana.
10. Check All Logs
journalctl -xe
Process kyu fail hua, error dekhne ke liye.
…and 5 more scenarios like managing zombie processes and renicing active jobs.
🚀 5 Hands-on DevOps Projects
Scenario: Server load high hai. Identify the issue.
1. Run htop. 2. Press ‘F6’ to sort by MEM. 3. Find top memory eater. 4. Check logs using tail -f /var/log/syslog.
Scenario: Nginx crash ho raha hai.
1. sudo systemctl stop nginx. 2. sudo systemctl start nginx. 3. Verify using systemctl is-active nginx.
Scenario: Unwanted python script consuming 90% CPU.
1. ps aux | grep python. 2. Identify PID. 3. kill 1234. 4. Verify process is gone.
Scenario: Large log compression task.
1. tar -czf backup.tar.gz /var/log &. 2. Use jobs to monitor. 3. Use disown to keep it running after logout.
Scenario: Create a Bash script to alert if CPU is > 80%.
#!/bin/bashCPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d. -f1)if [ $CPU -gt 80 ]; then echo "High CPU Alert!"; fi
Summary: Key Takeaways 🎯
1. PID is the key to control any process.
2. htop is your best friend for live monitoring.
3. kill -9 is a power you should use carefully.
4. systemctl manages the life cycle of your server services.
Next Step: Chapter 6 ka Quiz pass karein aur Certificate earn karein!