A runaway process consuming 100% of your CPU can cause websites to load slowly, game servers to lag, and SSH connections to freeze. Knowing how to quickly locate and handle high-CPU processes is a critical skill for every Linux server administrator.
In this guide, we show you how to inspect, isolate, and safely terminate or throttle high-CPU processes on a RivinCloud VPS.
1. Finding High-CPU Processes
Method A: Using ps (Fast & Scriptable)
To display the top 10 processes consuming the most CPU power:
ps aux --sort=-%cpu | head -n 11
This output prints the USER, PID (Process ID), %CPU, %MEM, TIME, and the exact COMMAND executed.
Method B: Using top
Launch top:
top
Press Shift + P inside top to sort processes by CPU utilization in descending order. Note the PID of the suspicious process.
Method C: Using pidof or pgrep
If you suspect a specific program (e.g., a node script or python bot) is causing problems:
pgrep -l node
2. Stopping High-CPU Processes Gracefully
Once you have identified the PID, never immediately kill it forcefully unless necessary.
Step 1: Send a Graceful Termination Signal (SIGTERM)
kill -15 <PID>
# or simply
kill <PID>
This instructs the process to save open files, close database connections, and exit cleanly.
Step 2: Forceful Kill (SIGKILL)
If the application is completely frozen and does not respond after 15-30 seconds:
kill -9 <PID>
[!WARNING] Using
kill -9terminates the process instantly at the kernel level. This can corrupt open database files or state caches if used indiscriminately.
Step 3: Terminating by Name with killall or pkill
sudo pkill -f problematic-script.py
3. Alternative: Throttling Instead of Killing
If a process is legitimate (such as a database backup or video rendering task) and you want it to run without hogging the whole CPU:
Using renice to Lower Priority
Linux scheduling priorities range from -20 (highest priority) to 19 (lowest priority).
sudo renice 15 -p <PID>
Using cpulimit
Install cpulimit to restrict a process to a specific maximum percentage (e.g., 50% CPU limit):
sudo apt install cpulimit -y
sudo cpulimit -p <PID> -l 50
Common Mistakes
- Killing system processes: Accidentally terminating
systemd,sshd, orkworkerprocesses. - Using
kill -9by default: Always attempt standardkill(SIGTERM) first. - Ignoring the root cause: Killing a process that immediately gets restarted by a supervisor loop without diagnosing why it crashed or looped.
Troubleshooting
- Process doesn't die even with
kill -9: The process is likely in an uninterruptible sleep state (Dstate intop), usually blocked waiting for hanging disk I/O or an unmounted NFS share. You must resolve the underlying storage freeze or reboot. - Zombie processes (
Zstate): Zombie processes are already dead and consume no CPU/RAM; they remain until their parent process acknowledges them. Restart the parent process to clear zombies.
Best Practices
- Use process managers like
pm2orsystemdwith resource limits configured (CPUQuota=80%in systemd unit files). - Keep system packages updated to avoid known memory leaks and infinite CPU execution bugs.
Frequently Asked Questions
What does %CPU over 100% mean in top?
Linux counts 100% per CPU core/thread. On a 4-core VPS, a multi-threaded application can show up to 400% CPU usage.
How do I identify which user launched a process?
The first column in ps aux indicates the user account that spawned the process.
Conclusion
Quickly identifying and resolving high-CPU bottlenecks keeps your RivinCloud VPS responsive and stable. Bookmark these commands for immediate troubleshooting during unexpected server spikes!
