How to Troubleshoot High CPU Usage in Linux
Introduction
High CPU usage can slow down your server and affect website performance. This guide shows you how to identify and fix the most common causes of high CPU usage in Linux.
Step-by-step Guide
- Check current CPU usage
- topn
- o usa:
- htop
- (If not installed:
sudo apt install htop)
- topn
- Identify the process consuming the most CPU
- In
toporhtop, look at the “%CPU” column. - ote the PID (Process ID) of the top-consuming process.
- In
- Get more info about the process
- ps -p PID -o %cpu,%mem,cmdn
- (Replace
PIDwith the actual process ID)
- (Replace
- ps -p PID -o %cpu,%mem,cmdn
- Kill or restart a problematic process (if needed)
- sudo kill -9 PIDn
- (Use with caution!)
- sudo kill -9 PIDn
- Check for cron jobs or scripts running in the background
- crontab -l
- Check system logs for errors
- sudo tail -n 100 /var/log/syslogn
- o para CentOS/RHEL:
- sudo tail -n 100 /var/log/messages
- sudo tail -n 100 /var/log/syslogn
- Monitor CPU usage over time
- sar -u 1 10n
- (If not installed:
sudo apt install sysstat)
- (If not installed:
- sar -u 1 10n
Recommendations
- Regularly monitor your server with
htoportop. - Investigate any unknown or suspicious processes.
- Optimize or update applications that use excessive CPU.
- Consider upgrading your VPS if you consistently hit CPU limits.
Call To Action
eed more power for your projects? Upgrade to a high-performance VPS! https://xernode.com/#pricing