🎯 Objective
Learn how to monitor, analyze, and troubleshoot running processes in Linux using system tools to identify performance issues, stuck processes, or resource overuse.
# 📘 What is a Process in Linux?
A process is a running instance of a program.
When a command or application runs in Linux, the system creates a process with its own:
Example:
Running:
firefoxcreates a Firefox process in the system.
# 🧠 Process States in Linux
# 🔍 Viewing Running Processes
Using ps
ps auxExplanation:
Example output fields:
View process tree
ps -ef --forestShows parent-child relationship between processes.
# 📊 Real-Time Process Monitoring
Using top
topShows:
Important keys inside top:
Using htop
Install:
sudo yum install htop -yRun:
htopFeatures:
# 🔎 Finding a Specific Process
Using grep
Example:
ps aux | grep nginxFinds Nginx processes.
Using pgrep
pgrep nginxShows only process IDs.
# 🧾 Process Priority
Each process has a priority value called nice value.
Run command with priority
nice -n 10 commandChange priority of running process
renice5 -p 1234Where 1234 = PID
# 🛑 Killing a Process
Sometimes processes hang or consume excessive resources.
Kill by PID
kill 1234Force kill process
kill -9 1234Signal 9 = SIGKILL
Kill by process name
pkill nginxor
killall nginx# 📈 Monitoring CPU Usage
Check CPU usage:
topor
mpstat# 📊 Monitoring Memory Usage
Check memory:
free -hExample output:
# 📁 Check Disk Usage
Sometimes processes fail due to disk full issues.
Check disk:
df -h# 🔍 Identify High Resource Processes
Sort by CPU usage:
ps aux --sort=-%cpuSort by memory:
ps aux --sort=-%mem# 🧪 Example Troubleshooting Scenario
Problem
Server is slow.
Step 1: Check CPU usage
topFind process using high CPU.
Step 2: Identify process
Example:
PID 2345 javaStep 3: Investigate process
ps -p 2345 -fStep 4: Restart or kill process
kill 2345or
kill -9 2345# 📜 Viewing Open Files by Process
Use:
lsof -p PIDExample:
lsof -p 1234Shows files opened by that process.
# 🌐 Viewing Process Network Connections
ss -tunapShows processes using network ports.
# 📑 Viewing System Logs
If process crashes:
journalctl -xeor
journalctl -u service-nameExample:
journalctl -u nginx# ⚠ Common Process Issues
High CPU usage
Check:
topFix:
Restart or kill process.
Zombie processes
Check:
ps aux | grep ZFix:
Restart parent process.
Memory leak
Symptoms:
Check:
topRestart service if needed.
# 🧰 Useful Process Commands
# ✅ Key Learning Points