How to Troubleshoot High CPU Usage on a Linux Server (Step-by-Step Guide)
If you manage a Linux server long enough, sooner or later you’ll have that heart-stopping moment:
You log in…
Run top…
And see your CPU stuck at 99–100%.
The server feels slow.
Users start complaining.
And your brain quietly whispers: “Please don’t crash…”
Don’t panic — this guide walks through how I usually troubleshoot high CPU usage on Linux in a calm, systematic way.
Nothing fancy. No magic. Just practical steps that work.
🔍 Step 1 — Confirm the CPU Problem
First, check real-time usage:
or, if installed:
You’ll see something like:
Key fields:
-
us= user processes (apps) -
sy= system/kernel -
id= idle (this is the “free CPU” value)
If id is close to 0.0%, your CPU is maxed out.
Then look at the process list — sorted by CPU by default in top.
You’ll typically see something like:
Congrats — you’ve found the main suspect.
🧠 Step 2 — Identify What That Process Actually Is
Get details using ps:
You might discover things like:
-
a PHP script looping
-
a Python script stuck
-
a MySQL query exploding
-
a Node.js process hogging CPU
Now at least you know what’s eating your server.
🛠 Step 3 — Restart or Kill (But Do It Wisely)
If it's a service, restart it the clean way:
or
or
If it’s totally stuck and not service-managed:
If it refuses to die:
⚠ Only use kill -9 when necessary — it forces termination.
📦 Step 4 — Check for Runaway Cron Jobs
Sometimes a script keeps looping every minute.
List cron jobs:
Also check:
Look for scripts that may run forever.
💾 Step 5 — Check Logs (The Truth Is Usually There)
Web logs:
System logs:
Database logs (mysql or postgresql) can also reveal slow queries.
I’ve fixed countless problems just by reading logs calmly.
🧪 Step 6 — Check If It’s Swap Thrashing
If RAM is low, CPU spikes because the system swaps.
Run:
If swap is heavily used → you need more RAM or need to optimize apps.
☁ Step 7 — Check Load Average (Are You Over Capacity?)
Run:
Example output:
Rule of thumb:
-
If load ≈ number of CPU cores → okay
-
If load ≫ cores → overloaded
Check cores:
If you have 2 cores and load is 10… yeah — upgrade time.
🛡 Bonus: Common Real-World Causes
Here are the most frequent culprits I’ve seen:
✔ A bad PHP/Python loop
✔ Bots hammering a website
✔ Heavy database query
✔ Backup script gone wrong
✔ Memory leak causing swap
✔ Misconfigured server
Once you recognize the patterns, troubleshooting becomes faster.
📌 Prevent This From Happening Again
Some habits that help:
-
Monitor with tools (Netdata, htop, Grafana, etc.)
-
Set resource limits
-
Optimize queries / code
-
Keep your software updated
-
Avoid running unknown scripts as root
Your server (and sleep schedule) will thank you 😄
🎯 Final Thoughts
High CPU usage on Linux is fixable — as long as you stay calm and work step-by-step:
1️⃣ Identify the process
2️⃣ Understand why it’s running
3️⃣ Fix the root cause
4️⃣ Prevent recurrence
Real sysadmins don’t panic — we diagnose.
(Okay… maybe we panic a little first. But quietly.)