Advertisement
linuxserver If your Linux server suddenly hits 100% CPU usage, websites slow down, commands lag, and the system becomes nearly unusable. This tutorial explains—step by step—why CPU spikes happen, how to diagnose the root cause using simple Linux commands, and how to fix it even if you’re a complete beginner.

Why Is My Linux CPU at 100%? (Beginner-Friendly Troubleshooting Guide)

5 Min Read Verified Content

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

top

Look at the column %CPU.

If you see something like:

1234 php-fpm 250%

or

mysqld 180%

That’s your culprit.

Use htop (if installed)

Much easier to read:

htop

Press:

  • F6 → sort by CPU

  • F3 → search a process

If you don’t have it:

sudo apt install htop -y # Debian/Ubuntu sudo yum install htop -y # CentOS/RHEL


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

php-fpm 100% php-fpm 99% php-fpm 98%

A script might be looping.

Check logs:

tail -f /var/log/php*/error.log

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:

mysqld 180%

Then MySQL is the problem.

Check slow queries:

mysqladmin processlist

Or:

SHOW PROCESSLIST;

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:

ss -tuna

Check connections to your web server:

netstat -an | grep :80 | wc -l

Check if one IP is abusing you:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

If an IP shows thousands of connections → block it:

sudo ufw deny from <IP>

or using firewall-cmd:

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<IP>" reject' sudo firewall-cmd --reload


## Step 5 — Check Background Jobs (Cron Jobs)


Sometimes a cron job runs too often or gets stuck.

List cron jobs:

crontab -l

Check running jobs:

ps aux | grep cron

Look in cron logs:

grep CRON /var/log/syslog

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:

systemctl status

Look for services constantly restarting.

Examples:

  • Apache restarting repeatedly

  • Node application crashing and respawning

  • Docker containers looping

To restart a suspicious service:

sudo systemctl restart service-name


## Step 7 — Check Disk Full (Yes, It Can Cause 100% CPU)


Run:

df -h

If root partition is 100% full, many processes break and CPU spikes.

Clear logs:

sudo journalctl --vacuum-size=100M

Clear apt cache:

sudo apt clean

Remove big log files:

sudo truncate -s 0 /var/log/*.log


## Step 8 — Check Load Average


In top, look at this line:

load average: 8.32, 7.10, 6.80

If your server has:

  • 1 CPU core → load > 1 = overloaded

  • 2 CPU cores → load > 2 = overloaded

  • 4 cores → load > 4 = overloaded

Check CPU cores:

nproc

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:

sudo systemctl restart php7.4-fpm sudo systemctl restart apache2 sudo systemctl restart nginx sudo systemctl restart mysql sudo systemctl restart docker

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 TypeHow to DiagnoseHow to Fix
One process high CPUtop, htopRestart or fix script
MySQL slowSHOW PROCESSLISTFix queries, add indexes
Apache overloadToo many connectionsEnable caching
AttackCheck IP logsBlock attacker
Cron job loopsCheck logsFix timing
Disk fulldf -hClear space
Too many servicessystemctlDisable 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.

Advertisement
Back to Linuxserver