Why Is My Linux CPU at 100%? (Beginner-Friendly Troubleshooting Guide)
# Why Is My Linux CPU at 100%? (Problem → Solution for Beginners)
CPU usage stuck at 100% is one of the most stressful Linux problems. Suddenly:
-
Your SSH session lags
-
Pages load slowly
-
Commands take forever
-
Your server feels frozen
Relax. CPU spikes usually come from something simple: a process looping, a web server overload, a runaway script, or a misconfiguration.
Let’s fix it using easy steps anyone can follow.
## Step 1 — Identify What Process Is Eating the CPU
Use top
Run:
Look at the column %CPU.
If you see something like:
or
That’s your culprit.
Use htop (if installed)
Much easier to read:
Press:
-
F6 → sort by CPU
-
F3 → search a process
If you don’t have it:
## Step 2 — Check If a Single Script Is Stuck in a Loop
This is common for PHP, Python, Node, or cron jobs.
Example: PHP script using 100% CPU
If top shows:
A script might be looping.
Check logs:
Common causes:
-
Infinite loops
-
Bad SQL queries
-
Bots hammering your site
-
Missing index causing slow DB queries
## Step 3 — Check for High MySQL CPU Usage
If you see:
Then MySQL is the problem.
Check slow queries:
Or:
Look for:
-
“Locked”
-
“Copying to tmp table”
-
Very long “Query”
-
Too many “Sleep”
Fixing slow MySQL queries often instantly fixes CPU.
## Step 4 — Check If Your Server Is Under Attack
A spike of CPU might be caused by:
-
Bot traffic
-
DDoS
-
Brute-force login attempts
-
Crawlers overloading your site
-
A sudden increase of visitors
Check number of active connections:
Check connections to your web server:
Check if one IP is abusing you:
If an IP shows thousands of connections → block it:
or using firewall-cmd:
## Step 5 — Check Background Jobs (Cron Jobs)
Sometimes a cron job runs too often or gets stuck.
List cron jobs:
Check running jobs:
Look in cron logs:
Examples of CPU-killer cron jobs:
-
Backup script that never finishes
-
Log rotation loop
-
Database dump running every minute
-
Script running thousands of times
## Step 6 — Check If a System Service Is Misbehaving
Run:
Look for services constantly restarting.
Examples:
-
Apache restarting repeatedly
-
Node application crashing and respawning
-
Docker containers looping
To restart a suspicious service:
## Step 7 — Check Disk Full (Yes, It Can Cause 100% CPU)
Run:
If root partition is 100% full, many processes break and CPU spikes.
Clear logs:
Clear apt cache:
Remove big log files:
## Step 8 — Check Load Average
In top, look at this line:
If your server has:
-
1 CPU core → load > 1 = overloaded
-
2 CPU cores → load > 2 = overloaded
-
4 cores → load > 4 = overloaded
Check CPU cores:
Small servers (1 vCPU) easily hit 100% usage.
## Step 9 — Restart the Offending Service (Temporary Fix)
If CPU is stuck at 100% and you want quick breathing room:
Examples:
But remember:
A restart is temporary — not a real fix.
## Step 10 — Final Fixes Based on What You Found
If MySQL is high CPU
→ Optimize queries, add indexes, increase buffer pools.
If PHP or Python is high CPU
→ Fix infinite loops or errors in app code.
If Apache/Nginx is overloaded
→ Reduce worker processes
→ Add rate limiting
→ Use caching (Redis, FastCGI cache)
If server is under attack
→ Block IPs
→ Enable rate limiting
→ Install fail2ban
If CPU is too small
→ Upgrade VPS (from 1 vCPU → 2 vCPU)
## Beginner-Friendly Checklist
| Issue Type | How to Diagnose | How to Fix |
|---|---|---|
| One process high CPU | top, htop | Restart or fix script |
| MySQL slow | SHOW PROCESSLIST | Fix queries, add indexes |
| Apache overload | Too many connections | Enable caching |
| Attack | Check IP logs | Block attacker |
| Cron job loops | Check logs | Fix timing |
| Disk full | df -h | Clear space |
| Too many services | systemctl | Disable unused services |
## Conclusion
A Linux server at 100% CPU can look scary, but the root cause is almost always something simple:
-
A script looping
-
A slow MySQL query
-
Web traffic spike
-
Cron job running too often
-
Misbehaving service
-
Server under attack
With the clear step-by-step process in this tutorial, even beginners can confidently diagnose and fix CPU overload problems.