How would you diagnose and resolve high CPU utilization on a Linux server in a production environment?

AtlassianDevOps Engineer3–5 YearsLinux
A systematic approach is crucial when diagnosing high CPU utilization on a Linux server. I would begin with `top` or `htop` to get a real-time overview of system activity. This immediately shows which processes are consuming the most CPU, the overall load average, and memory usage. Identifying the process or processes with high CPU usage is the first critical step, noting their PIDs.

Systematic Diagnosis Workflow

Once the high-CPU processes are identified, I’d use `ps auxf –pid ` to get more detailed information about the process, including its full command line, parent process, and current state. If it’s a known application, I’d check its logs for any errors or unusual activity. For deeper inspection, `strace -p ` can reveal system calls the process is making, indicating if it’s CPU-bound, I/O-bound (e.g., waiting on disk reads), or stuck in a loop. `lsof -p ` helps identify open files or network connections, which can be relevant if the process is waiting on external resources. I would also check `vmstat` or `sar` for system-wide metrics like CPU wait I/O, context switches, and network activity to differentiate between application issues and broader system resource contention.

Best practice

Always start with non-intrusive tools and progressively move to more detailed, potentially impactful ones (like `strace`). Avoid making immediate changes or restarting services without understanding the root cause, as this often just masks the problem temporarily and makes it harder to diagnose if it recurs. Document your diagnostic steps and findings. If a configuration change or software update caused the issue, rolling back is a quick fix, but understanding *why* it caused the issue is key to preventing future occurrences, possibly by adding more robust monitoring or conducting better pre-deployment testing.

Edge case interviewers probe for

An interesting edge case is when high load average doesn’t correlate with high CPU utilization shown by `top`. This usually indicates an I/O wait issue, where processes are waiting for disk or network operations to complete, causing them to be in an uninterruptible sleep state. Tools like `iostat -xz` will show high disk utilization and wait times, while `vmstat` will show a high `wa` (wait) percentage. Another less common scenario is CPU stealing in virtualized environments, where the hypervisor is oversubscribed. This can be seen in `vmstat`’s `st` column or `sar -u ALL`.

Common mistake

A common mistake is focusing solely on the “user” CPU percentage without considering “system” CPU or “iowait.” High system CPU can indicate kernel-level issues, inefficient system calls, or excessive context switching, while high iowait points to I/O bottlenecks. Another error is to blindly kill processes; while it may alleviate the immediate symptom, it doesn’t solve the underlying problem and can lead to data corruption or service instability. It’s also important to differentiate between CPU usage and load average – a high load average with low CPU could signify I/O bottlenecks, not necessarily CPU starvation.

What the interviewer is checking

The interviewer is checking your practical, hands-on Linux troubleshooting skills, your ability to think systematically under pressure, and your knowledge of various diagnostic tools. They want to see if you can differentiate between different types of CPU consumption (user, system, I/O wait), identify the root cause, and propose a robust solution beyond a quick fix. Your understanding of system internals, proactive monitoring, and ability to communicate your thought process are also being assessed.
Imagine your computer is a busy coffee shop, and the CPU is the barista. When your computer’s CPU is running at high utilization, it’s like the barista is constantly making drinks, running back and forth, barely keeping up, and a long line of customers (tasks) is forming. To figure out why the barista is so busy, you first look over the whole shop to see who is ordering what (like using `top` or `htop` to see which programs are consuming the most processing power). You quickly spot that one customer, let’s say “The Video Editor,” is ordering extremely complex, multi-step drinks, slowing everything down.Now that you know “The Video Editor” is the main culprit, you need to understand *why* their orders are so demanding. Is their complex drink recipe just inherently time-consuming (a CPU-bound application)? Or are they constantly running to the back to get more milk from the fridge because the main supply is empty (an I/O bottleneck)? You might check their order ticket (`ps auxf`), see them repeatedly ask for a specific ingredient that’s always out of stock (`strace` showing repeated file access issues), or notice them constantly dropping and picking up tools (`high context switching`). By understanding the *type* of work making the barista busy, you can then fix the problem, perhaps by getting “The Video Editor” a specialized machine or ensuring the milk fridge is always stocked.

Why interviewers ask this

Interviewers use this question to evaluate a candidate’s practical troubleshooting skills, their depth of knowledge about Linux internals, and their ability to perform under pressure in a critical production scenario. It’s a real-world problem that demands systematic thinking.

What a strong answer signals

A strong answer demonstrates a structured, calm approach to problem-solving, deep familiarity with core Linux diagnostic tools, and an understanding of different performance bottlenecks (CPU-bound, I/O-bound, memory-bound). It signals an ability to identify root causes rather than just symptoms.

Common follow-ups

  • How do you distinguish between high user CPU and high system CPU utilization, and what does each imply?
  • What if top shows a high load average but low CPU utilization across all cores? How would you investigate?
  • How would you automate the detection and alerting for this type of issue using standard monitoring tools?

Advanced variation

An advanced variation might ask: “Given a containerized application exhibiting high CPU, how would your diagnostic approach change compared to a traditional VM, specifically considering host vs. container metrics? How would you use cgroups or kernel-level tracing (e.g., eBPF) for deeper insights?”

A web service deployed on a Linux VM intermittently experiences slow response times, with monitoring alerts indicating high CPU utilization on its host. Initial investigation with htop shows a Python process tied to the web service consuming nearly 100% of one CPU core. Further analysis with strace -c -p <PID> reveals an abnormally high number of stat() calls, indicating the application is constantly checking for file existence. Reviewing the application’s configuration and code identifies a misconfigured cache path that leads to repeated, unsuccessful file lookups. Correcting the cache path configuration immediately reduces stat() calls and CPU utilization, restoring normal service performance.

diagnosis_script.sh
#!/bin/bash
# Script to collect initial CPU diagnosis data

echo "--- Top processes by CPU (first 10) ---"
top -bn1 | head -n10
echo ""

echo "--- CPU core utilization ---"
mpstat -P ALL 1 1
echo ""

echo "--- Load average over last 1, 5, and 15 minutes ---"
uptime
echo ""

echo "--- Disk I/O stats (potential cause for high iowait) ---"
iostat -xz 1 2 | tail -n +4
echo ""

echo "--- Current network connections (high activity can consume CPU) ---"
sudo netstat -tunap | head -n 10
echo ""

# Example: Find a specific process causing high CPU and get its open files
# high_cpu_pid=$(top -bn1 | awk '{if(NR>7 && $9>5.0) print $1;}' | head -n1)
# if [ -n "$high_cpu_pid" ]; then
#   echo "--- Open files for PID $high_cpu_pid ---"
#   sudo lsof -p $high_cpu_pid
# fi
High CPU Symptom Initial Check(top, htop) Process Deep Dive(ps, strace, lsof) System Metrics(vmstat, sar, iostat) Root Cause Identified Implement Resolution
  1. 1Always begin diagnosis with `top` or `htop` for an immediate, high-level overview of system and process resource consumption.
  2. 2Utilize `ps`, `strace`, `lsof`, and `netstat` for detailed, process-specific insights to pinpoint the exact nature of the CPU usage.
  3. 3Distinguish between CPU-bound, I/O-bound, and context-switching related issues to apply the correct troubleshooting and resolution strategies.
  4. 4Focus on identifying and addressing the root cause, rather than merely mitigating symptoms, to ensure a lasting solution and prevent recurrence.
  5. 5Proactive monitoring with appropriate alerting thresholds is critical for anticipating and preventing high CPU utilization issues before they impact users.