Advertisement
linuxserver Is your Linux server suddenly using 100% CPU? Learn how to diagnose and fix high CPU usage using real-world tools like top, htop, ps, systemctl, and logs — explained in a practical way.

How to Troubleshoot High CPU Usage on a Linux Server (Step-by-Step Guide)

5 Min Read Verified Content

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:

top

or, if installed:

htop

You’ll see something like:

%Cpu(s): 97.3 us, 2.5 sy, 0.0 ni, 0.2 id, ...

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:

1234 www-data 95.0 /usr/bin/php-fpm

Congrats — you’ve found the main suspect.


🧠 Step 2 — Identify What That Process Actually Is

Get details using ps:

ps aux | grep 1234

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:

sudo systemctl restart apache2

or

sudo systemctl restart nginx

or

sudo systemctl restart php8.2-fpm

If it’s totally stuck and not service-managed:

sudo kill 1234

If it refuses to die:

sudo kill -9 1234

⚠ 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:

crontab -l

Also check:

sudo ls /etc/cron.*

Look for scripts that may run forever.


💾 Step 5 — Check Logs (The Truth Is Usually There)

Web logs:

/var/log/nginx/error.log /var/log/apache2/error.log

System logs:

/var/log/syslog /var/log/messages journalctl -xe

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:

free -h

If swap is heavily used → you need more RAM or need to optimize apps.


☁ Step 7 — Check Load Average (Are You Over Capacity?)

Run:

uptime

Example output:

load average: 1.52 2.10 3.45

Rule of thumb:

  • If load ≈ number of CPU cores → okay

  • If load ≫ cores → overloaded

Check cores:

nproc

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.)

Advertisement
Back to Linuxserver