Table of Contents
High CPU usage can slow down your VPS, cause timeouts, and crash services. Finding the exact process and fixing it quickly is critical for stability.
Step 1: Check Current CPU Usage
Start by viewing real-time CPU usage.
top
Press q to exit. Look for processes with high %CPU.
Step 2: Use htop for a Clearer View
htop provides a more readable interface.
sudo apt update
sudo apt install htop -y
htop
Sort by CPU usage using F6.
Step 3: Identify the Problematic Process
Once you find the process name and PID, inspect it.
ps -fp PID
Replace PID with the actual process ID.
Step 4: Check If the Process Is a Service
Many high CPU issues come from system services.
sudo systemctl status service_name
If the service is misbehaving, logs usually explain why.
Step 5: Analyze CPU Usage History
Check whether CPU spikes are constant or temporary.
uptime
High load average compared to CPU cores indicates overload.
Step 6: Restart or Stop the Process
Restarting often fixes runaway CPU usage.
sudo systemctl restart service_name
Or stop it completely if not required.
sudo kill PID
Step 7: Limit CPU Usage for a Process
Prevent a single process from consuming all CPU.
sudo apt install cpulimit -y
sudo cpulimit -p PID -l 50
This limits the process to 50% CPU usage.
Step 8: Check for Common Causes
High CPU is often caused by web servers, databases, Docker containers, or cron jobs.
crontab -l
docker ps
You may also want to review this related article: How to Fix Services That Fail After Server Reboot
Optional Step: Add Monitoring to Prevent Future Issues
Monitoring helps detect CPU spikes before they cause downtime.
htop
uptime