Linux interview question · Most asked

A Linux server has high CPU usage. How do you find the cause?

Scenario Asked in DevOps Engineer · Site Reliability Engineer (SRE) interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

Confirm what kind of CPU time it is, then find the process and, if needed, the code path. top or htop shows the busiest processes and the split between user (us), system (sy), I/O wait (wa) and steal (st) time; that split decides where to look next.

Longer Answer

  1. uptime / top: load average and the CPU split. High us is the application; high sy is the kernel (syscalls, context switches); high wa means waiting on disk, not really CPU; high st on a VM means the hypervisor is taking CPU (noisy neighbour or burst credits exhausted).
  2. Which process: sort by CPU in top (P), ps -eo pid,comm,%cpu --sort=-%cpu | head, and pidstat 1 for per-process trends. Check threads with top -H -p PID.
  3. Why: perf top -p PID or a flame graph for native code; language tools for runtimes (jstack / async-profiler for the JVM, py-spy for Python). Look for a hot loop, a regex, GC pressure, or a spike in traffic.
  4. Context: did it start with a deploy, a cron job, a traffic change? Compare with metrics history.
  5. Mitigate while investigating: scale out, roll back, rate-limit, or renice a batch job.

Example

top -o %CPU                 # busiest processes; press 1 for per-core view
pidstat -u 1 5              # per-process CPU every second
top -H -p 4123              # threads of one process
sudo perf top -p 4123       # hottest functions

Key Points

  • Read the CPU split: us, sy, wa, st.
  • Find the process, then the thread, then the code path.
  • High wa is I/O, high st is the hypervisor.
  • Correlate with deploys and traffic; mitigate first.

Explanation

What interviewers look for

A structured path from symptom to root cause, and knowing what each CPU field means.

More Linux questions

← All Linux questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake