Tracking Down High CPU on Linux
A field-tested workflow for finding which process burns your CPU and whether the time is user, system, or iowait.
Key takeaways
- Find the process with top -o %CPU or pidstat 1, then read the CPU states line.
- High us means profile the code with perf top; high sy means count syscalls with strace -c; high wa is storage, and high st is a noisy hypervisor.
- Drill from process to thread with top -H before profiling.
On this page
To debug high CPU on Linux, find the process with top -o %CPU or pidstat 1, then read the %Cpu(s) line to see what kind of time it burns. High us means profile the code with perf top -p PID. High sy means count syscalls with strace -c -p PID. High wa is storage; high st is the hypervisor.
Verified against
procps-ng top and vmstat man pages, sysstat 12.8.0 (pidstat), strace 7.1, perf from the Linux source tree, against the man7.org manual pages and the kernel.org perf-security and Yama docs. Checked October 2026.
A box pages at 3am with CPU pinned. Before the reboot button, the goal is narrow: which process, and what kind of CPU time? Those two facts point at completely different fixes. For the wider picture (memory pressure, disk saturation), see the Linux troubleshooting guide. Here we stay on CPU. The outputs below are illustrative.
Step 1: find the process
top -o %CPU
top - 03:14:22 up 41 days, 2:07, 1 user, load average: 7.81, 6.02, 4.10
%Cpu(s): 18.3 us, 71.2 sy, 0.0 ni, 6.1 id, 0.0 wa, 0.0 hi, 4.4 si, 0.0 st
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28471 app 20 0 4821140 612204 18932 R 388.4 3.8 91:22.14 api-server
1042 root 20 0 912304 44120 12008 S 12.6 0.3 14:02.90 node_exporter
api-server at 388% is nearly four full cores. The summary line already tells a story: 71.2 sy means most of the time is in the kernel, not application code. Hold that thought.
top is an instantaneous snapshot. pidstat gives a clean per-process rate over an interval, split into user and system, which is easier to trust:
pidstat -u -p 28471 1 3
03:15:01 UID PID %usr %system %guest %wait %CPU CPU Command
03:15:02 1001 28471 19.0 72.0 0.00 0.00 91.0 2 api-server
03:15:03 1001 28471 18.0 73.0 0.00 0.00 91.0 1 api-server
Step 2: read the CPU breakdown
The %Cpu(s) line is the most under-used diagnostic on the box. The top(1) man page defines each field; here is what each one means for the fix:
- us: user code that is not niced. The fix lives in the application or its config.
- sy: kernel time. High
symeans the app is hammering the kernel: tinyread/writecalls, lock contention, or a context-switch storm. - wa: idle while waiting for I/O to complete. Not a CPU problem at all; adding cores will not help. See diagnosing high load average for that path.
- si: software interrupts, mostly network packet processing. Points at network load or a single-queue NIC.
- st: time the hypervisor took from this VM. A noisy neighbour you cannot fix from inside the guest; resize or move the instance.
So 18 us / 71 sy / 4 si is not a hot application loop. It is a syscall or context-switch problem.
Step 3: find the hot thread
A process at 388% is several threads, and a 40-thread app rarely melts down evenly. top -H shows individual threads:
top -H -p 28471
PID USER PR NI VIRT RES S %CPU %MEM TIME+ COMMAND
28493 app 20 0 4821140 612204 R 98.7 3.8 22:14.02 worker-3
28494 app 20 0 4821140 612204 R 97.9 3.8 21:58.71 worker-4
ps -T -p 28471 -o pid,tid,pcpu,comm --sort=-pcpu | head -4
PID TID %CPU COMMAND
28471 28493 98.7 worker-3
28471 28494 97.9 worker-4
28471 28471 1.1 api-server
For JVM services, convert the TID to hex (printf '%x\n' 28493 gives 6f4d) and search a jstack dump for nid=0x6f4d to get the Java stack of the hot thread.
Step 4: profile what those threads are doing
High user time: sample stacks with perf. perf top -p profiles an existing PID live, no restart needed:
sudo perf top -p 28471
Overhead Shared Object Symbol
41.20% api-server [.] json_tokenize
18.60% libc.so.6 [.] __memmove_avx_unaligned
11.04% api-server [.] regex_match_backtrack
A JSON tokenizer and a backtracking regex are eating over half the time. For a record you can turn into a flame graph:
sudo perf record -F 99 --call-graph dwarf -p 28471 -- sleep 20
sudo perf report --stdio --no-children | head -30
--call-graph dwarf recovers stacks from binaries built without frame pointers; the default fp mode shows [unknown] frames for those.
High system time: count syscalls with strace.
sudo strace -f -c -p 28471
strace: Process 28471 attached
^C
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
68.44 4.812301 6 782140 read
22.10 1.554002 4 381004 futex
8.90 0.625810 7 88201 write
Hundreds of thousands of read and futex calls in a few seconds explain the 71% sys time: tiny unbuffered reads plus lock contention. The fix is buffering and less lock churn, not more CPU. The man page warns that a traced process runs more slowly, so keep the window short on production; --seccomp-bpf reduces the cost when you filter to specific syscalls.
Context-switch storm: confirm with vmstat. cs in vmstat 1 is context switches per second. Values in the hundreds of thousands, together with futex at the top of strace, mean threads fighting over a lock.
The errors you hit while profiling
| Error text | Cause | Fix |
|---|---|---|
Error: Access to performance monitoring and observability operations is limited. | kernel.perf_event_paranoid blocks unprivileged perf | Run with sudo, grant CAP_PERFMON, or lower the sysctl temporarily |
strace: attach: ptrace(PTRACE_SEIZE, 28471): Operation not permitted | Yama ptrace_scope is 1 or higher, or missing CAP_SYS_PTRACE in a container | Use sudo; in containers add --cap-add=SYS_PTRACE |
WARNING: perf not found for kernel 6.8.0-45 | Ubuntu's perf wrapper has no tools package for the running kernel | sudo apt install linux-tools-$(uname -r) |
perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error 1 (Operation not permitted) | Container seccomp profile blocks perf_event_open | Profile from the host with -p on the host PID |
Stacks full of [unknown] | Binary built without frame pointers, or stripped | --call-graph dwarf, install debug symbols |
Per the kernel's Yama docs, ptrace_scope 3 cannot be changed once set, so on hardened hosts strace attach is simply unavailable until reboot. Fall back to perf trace or the eBPF tools in debugging latency with eBPF and bpftrace.
Common causes, quick reference
- Busy loop or spin: 100% user on one thread,
perf topflat on one function. A poll loop with no backoff. - GC pressure:
perf topheavy in the runtime's collector. Raise heap size or cut allocation rate. - Regex or JSON hotspots: pathological backtracking or giant payloads. Cap input size, precompile patterns, swap the parser.
- Context-switch storm: high sys, huge
cs,futexin strace. Lock contention or too many runnable threads. - iowait masquerading as CPU: high wa, low us and sy. Go profile the disk.
Where this breaks
Inside a container with a CPU limit, the box can look idle while your process is throttled: check nr_throttled in the cgroup's cpu.stat before blaming code. Interpreted runtimes (Python, Node, Ruby) show up in perf as interpreter frames unless you enable their perf-map support, so a language profiler (py-spy, --cpu-prof) is often faster. And short-lived processes that fork and exit thousands of times a second never sit at the top of top; high sy with no obvious culprit is the hint, and execsnoop-style eBPF tools catch them.
Questions people ask
How do I find which process is using the most CPU on Linux?
Run top -o %CPU for a live sorted view, or pidstat -u 1 5 for per-process rates averaged over five seconds, which is more reliable than a single snapshot. ps -eo pid,pcpu,comm --sort=-pcpu | head gives a one-shot list for scripts. Then press H in top, or run top -H -p PID, to see which thread inside that process is hot.
What does high sy (system) CPU mean?
It means the CPU spends its time in the kernel on behalf of processes: system calls, context switches, page faults and network stack work. The usual causes are many tiny reads or writes, lock contention showing as futex calls, or too many threads. Attach strace -c -p PID for a few seconds to count syscalls, and check the cs column in vmstat 1.
Is high iowait a CPU problem?
No. wa counts time the CPU was idle while I/O was outstanding, so it is really a storage signal. More cores will not help. Use iostat -x 1 to find the slow device and pidstat -d 1 to find the process issuing the I/O, then fix the disk, the NFS mount, or the workload's access pattern.
The call we'd make
Read the %Cpu(s) line first; it decides everything. High user means profile with perf and fix the hot function. High system means count syscalls with strace and cut the kernel chatter, usually with buffering or less lock contention. High iowait means walk away from CPU and chase storage. High steal means resize or migrate. Then drill from process to thread to function so the fix lands on the line that matters, not on a guess.
Sources
Cite this article
Kiril Urbonas (2026). Tracking Down High CPU on Linux. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/debug-high-cpu-linux
[Tracking Down High CPU on Linux](https://www.devopsness.com/blog/debug-high-cpu-linux) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Linux
Explore more articles in this category
Linux Performance Tuning for Containers and Kubernetes Nodes
Container performance problems usually live in the node kernel, not your app. Here is what we tune, why, and how we measure before touching anything.
Linux TCP Tuning for High-Throughput Services
A proxy that stalls with the CPU half-idle is often hitting kernel TCP defaults, not the hardware. The sysctls to change and how to measure each one.
Linux Troubleshooting: The Complete Guide
When a Linux box misbehaves, the same dozen problems come up again and again. This is the map: what each symptom means and the fast path to the fix.
You might have missed
Evergreen posts worth revisiting.