How do you troubleshoot high CPU usage on a Linux server?
Systematic CPU investigation:
- top / htop: Identify the process consuming CPU. Note: is it user space or kernel (
%usvs%sy)? - ps aux –sort=-%cpu: Snapshot of top CPU consumers.
- perf top: See which kernel functions are hot.
- strace -p <PID>: Trace system calls to understand what a process is doing.
- vmstat 1: Observe context switches (
cs) and interrupts (in).
Common causes: runaway application bug, CPU-intensive query (full table scan), kernel work from high I/O (softirqs), insufficient CPU for the workload.