How To Check Cpu In Linux

12 min read

Understanding the hardware powering your Linux system is fundamental for system administration, performance tuning, and troubleshooting. The Central Processing Unit (CPU) acts as the brain of your computer, and knowing how to inspect its architecture, core count, clock speeds, and real-time utilization is a critical skill. Whether you are provisioning a new server, debugging a sluggish application, or simply verifying virtual machine specifications, Linux provides a solid toolkit for querying processor information. This guide explores the most effective commands and files to check CPU details in Linux, ranging from static hardware specifications to dynamic performance metrics.

Viewing Static CPU Information

Before diving into live performance data, it is often necessary to understand the physical and logical capabilities of the processor. Linux exposes this static data primarily through the /proc filesystem and specialized command-line utilities That's the part that actually makes a difference..

The /proc/cpuinfo File

The most direct way to inspect CPU hardware details is reading the virtual file /proc/cpuinfo. This file does not exist on a physical disk; it is a runtime interface provided by the kernel. It lists every logical processor (thread) available to the system, detailing specifications for each.

To view the full output, run:

cat /proc/cpuinfo

The output is verbose. Key fields to look for include:

  • processor: The ID of the logical core (starting from 0). But * vendor_id: The manufacturer (e. On top of that, g. , GenuineIntel, AuthenticAMD). Practically speaking, * model name: The marketing name of the CPU (e. g., Intel(R) Core(TM) i7-9750H CPU @ 2.In real terms, 60GHz). * cpu cores: The number of physical cores per socket.
  • siblings: The number of logical threads per socket.
  • cpu MHz: The current operating frequency. Consider this: * cache size: The size of the L2 or L3 cache. * flags: A list of supported instruction set extensions (e.g., avx2, aes, vmx for virtualization).

Pro Tip: To get a concise summary without the repetition for every thread, pipe the output through grep and sort -u:

cat /proc/cpuinfo | grep -E '^(processor|vendor_id|model name|cpu cores|siblings|cpu MHz|cache size|flags)' | head -20

Using lscpu for Human-Readable Architecture

While /proc/cpuinfo is raw data, the lscpu command parses that data (and sysfs) to present a clean, structured summary of the CPU architecture. It is part of the util-linux package and is installed by default on almost all distributions.

Run it simply by typing:

lscpu

The output organizes information into logical categories:

  • Architecture: x86_64, aarch64, ppc64le, etc. Consider this: * CPU op-mode(s): 32-bit, 64-bit support. * Byte Order: Little Endian or Big Endian. Think about it: * CPU(s): Total number of logical CPUs (Threads). * Thread(s) per core: Hyper-threading / SMT factor.
  • Core(s) per socket: Physical cores per physical package.
  • Socket(s): Number of physical CPU sockets.
  • NUMA node(s): Non-Uniform Memory Access topology. In practice, * Model name: Full processor name. Now, * CPU max/min MHz: Frequency scaling limits. * Flags: Instruction set flags (same as /proc/cpuinfo).

lscpu is generally the preferred starting point for a quick architectural overview because it calculates the topology (Sockets × Cores × Threads) automatically.

Detailed Hardware Enumeration with lshw and dmidecode

For the most authoritative hardware inventory—often required for asset management or warranty checks—use lshw (List Hardware) or dmidecode. These tools query the SMBIOS/DMI tables provided by the system firmware (BIOS/UEFI).

Using lshw (requires root):

sudo lshw -class processor

This outputs a hierarchical description including the product name, vendor, physical id, bus info, width (64-bit), capabilities, and specific configuration details like enabled cores and threads.

Using dmidecode (requires root):

sudo dmidecode -t processor

dmidecode is invaluable for discovering the Socket Designation, Manufacturer, Version, Voltage, External Clock, Max Speed, and Current Speed. It also reports the Status (Populated/Enabled) and Upgrade capabilities (e.Think about it: g. , Socket LGA1151).

Monitoring Real-Time CPU Performance

Static specs tell you what the hardware can do; dynamic tools tell you what it is doing. Linux offers several standard utilities for observing live utilization, load averages, and frequency scaling.

The Classic top and Modern htop

top (Table of Processes) is the ubiquitous standard. It provides a dynamic, updating view of system summary information (uptime, load average, CPU states) and a list of processes That's the part that actually makes a difference. And it works..

Key CPU-related columns in the summary area:

  • %Cpu(s):
    • us (user): Time running un-niced user processes. Worth adding: * sy (system): Time running kernel processes. * ni (nice): Time running niced user processes.
    • id (idle): Time spent in the kernel idle handler.
    • wa (iowait): Time waiting for I/O completion.
    • hi (hardware interrupts): Time servicing hardware interrupts. So naturally, * si (software interrupts): Time servicing software interrupts. * st (steal): Time stolen by the hypervisor (relevant in VMs).

Press 1 while top is running to toggle the display of individual CPU core statistics The details matter here. That alone is useful..

htop is an interactive, colorized, and more user-friendly alternative (often needs installation via apt install htop or dnf install htop). It features:

  • Vertical bar graphs for each core (color-coded by user/sys/io-wait/steal).
  • Memory and Swap bars.
  • Mouse support for scrolling and killing processes.
  • Tree view (F5) for process hierarchy.

The System Activity Reporter: sar

For historical analysis and scripting, sar (part of the sysstat package) is the gold standard. It collects, reports, and saves system activity information.

To see CPU utilization sampled every 2 seconds for 5 intervals:

sar -u 2 5

Output columns include %user, %nice, %system, %iowait, %steal, and %idle. This is essential for generating performance reports or feeding data into monitoring systems like Prometheus or Grafana.

To check historical data collected by the sysstat cron job (usually stored in /var/log/sa/saDD):

sar -u -f /var/log/sa/sa$(date +%d -d yesterday)

Per-Processor Statistics with mpstat

While sar gives a system-wide average, mpstat (Multi-Processor Statistics) reports activities for each available processor. This is critical for identifying CPU affinity issues or single-threaded bottlenecks where one core is pegged at 100% while others are idle Not complicated — just consistent. That's the whole idea..

Run:

mpstat -P ALL 1
  • -P ALL: Reports for all CPUs.

Per‑Processor Statistics with mpstat – Going Beyond the Averages

While sar gives you a single set of percentages that represent the whole machine, mpstat breaks those numbers down per available processor. This makes it invaluable when you suspect that one core is monopolizing the CPU—perhaps because of an application that only uses a single thread—or when you want to trace latency patterns after a recent upgrade that may have introduced uneven load distribution That alone is useful..

Basic invocation

mpstat -P ALL 1

This displays a snapshot taken every second (the “1” argument tells mpstat to report the most recent interval) for all CPUs (ALL). By default it prints three main columns for each line:

Column Meaning
?? (or similar header) Processor index (e.g.

If you want more than one sample, change the numeric argument before the comma:

mpstat -P ALL 2 6   # last six seconds of data (one sample per second)

Common variations include:

  • Selecting a subset of CPUs
    mpstat -P 0,3 1   # CPUs 0 through 3, one interval
    
  • Focusing on a particular process group
    mpstat -p  1   # e.g., PID 1234
    
  • Filtering by CPU type or mode

Advanced mpstat usage patterns

1. Directing output to a file or a pipe

mpstat accepts the same redirection syntax as any other Unix command.

mpstat -P ALL 2 10 > /tmp/cpu_monitor.log

The above captures ten one‑second samples for every logical CPU into a log file, which can later be parsed by awk, grep, or a custom script And that's really what it comes down to. Took long enough..

If you prefer to stream the data into another program, a pipe works just as well:

mpstat -P 0,1 1 | grep -E '^0|^1' | awk '{print $2,$3}' | while read usr sys; do
    # Example: trigger an alert when user‑space usage on core 0 exceeds 80 %
    if (( $(echo "$usr > 80" | bc -l) )); then
        echo "$(date) – high user load on core 0" | mail -s "CPU alert" admin@example.com
    fi
done

2. Sampling a specific time window

The -I flag lets you define the interval between reports, while the final numeric argument tells mpstat how many seconds of data to retain.

mpstat -I 5 -P ALL 30 5   # 5‑second interval, keep the last 5 samples (30 seconds total)

This is handy when you need a short‑term view of a bursty workload without flooding the console.

3. Filtering by CPU type or mode

-P can be combined with the -u (user) or -s (system) switches to focus on a subset of the metrics that mpstat reports.

mpstat -P 2 -u 1          # only user‑space percentages for CPU 2
mpstat -P ALL -s 0.1 1   # system‑space percentages for every core, sampled each second

When you are troubleshooting

When you are troubleshooting performance anomalies, the first step is to capture a clear snapshot of how each logical core behaves over a short, reproducible window. A typical workflow starts with a one‑second interval that lasts long enough to smooth out transient spikes:

mpstat -P ALL 1 5

This command records five consecutive samples, giving you a concise history without overwhelming the console. If you suspect that a particular core is the source of the problem, narrow the focus:

mpstat -P 2 1 10

Here the output is limited to CPU 2 and refreshed every second for ten seconds, allowing you to watch the evolution of user‑space and kernel‑space activity on that core alone Simple, but easy to overlook..

Correlating mpstat data with other subsystems

mpstat reports only CPU‑centric counters, so pairing its output with I/O metrics yields a more complete picture. A quick way to do this is to run iostat in parallel:

iostat -x 1 5 &
mpstat -P ALL 1 5
wait

The two logs can then be merged with paste or join to see, for example, whether a high %iowait on a core coincides with elevated disk service times.

Automating alerts

For production environments, manual inspection is rarely sufficient. A lightweight script can parse mpstat’s output in real time and trigger notifications when thresholds are crossed. The following example monitors core 0 and sends an email when user‑space utilization exceeds 80 % for two consecutive samples:

mpstat -P 0 1 | awk 'NR>1 {usr=$4; if (usr>80) {last++} else {last=0}; if (last>=2) {system("mail -s \"CPU alert\" admin@example.com <<< \"High user load on core 0: "usr"%\")}}' &

The awk loop keeps a running count of consecutive “high‑load” readings, reducing false positives caused by momentary bursts.

Handling offline or isolated CPUs

On systems where some logical processors are disabled (e.g., due to hyper‑threading constraints or CPU affinity policies), the -P option still works, but you may need to specify a range that includes only the online cores:

mpstat -P 0-3 1

If you want to verify that a newly enabled core is participating correctly, run the command before and after the change and compare the number of columns in the header.

Interpreting the less‑obvious fields

  • %iowait: indicates time the CPU spends waiting for I/O completion. Persistent values above 5 % often point to storage bottlenecks.
  • %steal (when running under a hypervisor): shows cycles taken away by the hypervisor on behalf of another virtual machine. Elevated percentages suggest over‑commitment.
  • %hi and %si: reflect hardware and software interrupt activity. Spikes here can be triggered by device drivers, network cards, or frequent context switches.

Understanding the relationship between these fields and the overall load average (uptime or sar) helps pinpoint whether the issue is CPU‑bound, I/O‑bound, or a combination thereof.

Complementary tools

While mpstat excels at per‑core CPU accounting, it is often most powerful when used alongside:

  • sar – a sysstat utility that can record and replay a broader set of metrics, including memory, paging, and network activity.
  • vmstat – provides a quick view of processes, memory, and swap, useful for spotting overall system imbalance.
  • top/htop – interactive process‑level views that let you verify whether high

high CPU usage is attributable to specific applications or system threads.

  • perf – for deep profiling of CPU cycles, cache misses, and branch prediction behavior when you need to drill down into kernel or user‑space hot paths.
  • pidstat – another sysstat companion that breaks down CPU, I/O, and memory usage per process, making it easy to correlate mpstat’s aggregate numbers with the actual workload generators.

Building a repeatable diagnostic workflow

A practical, repeatable workflow for CPU performance investigations might look like this:

  1. Baseline capture – Run mpstat -P ALL 1 10 during a known‑good period and archive the output.
  2. Continuous monitoring – Deploy a lightweight collector (e.g., a systemd timer that appends mpstat -P ALL 1 1 to a daily log) so you have historical context when an anomaly appears.
  3. Alerting layer – Use the awk‑based snippet above (or a more dependable Prometheus node‑exporter + Alertmanager stack) to notify on‑call engineers before users feel the impact.
  4. Targeted drill‑down – When an alert fires, immediately run pidstat -u 1 5 and perf top -e cycles:u to identify the offending process and function.
  5. Correlation – Merge the CPU data with iostat, sar -n DEV, and application logs to confirm whether the root cause is compute‑bound, I/O‑bound, or contention‑related (e.g., lock contention showing up as high %sys or %hi).
  6. Remediation & verification – Apply the fix (code optimization, scheduler tuning, storage upgrade, VM resizing) and re‑run the baseline capture to verify the metric profile has returned to normal.

Closing thoughts

mpstat is deceptively simple: a single command that prints a handful of percentages. That's why yet those percentages are the vital signs of every logical processor in your system. By mastering its options—per‑core reporting, custom intervals, JSON output for scripting, and integration with the broader sysstat suite—you gain a low‑overhead, always‑available lens into CPU behavior that works on any Linux box, from a Raspberry Pi to a 256‑core cloud instance.

The real power emerges when you stop treating mpstat as a one‑off diagnostic and start treating its output as a continuous data stream: logged, alerted, correlated, and ultimately acted upon. In that regime, the tool ceases to be a “quick check” and becomes the backbone of a proactive performance‑engineering culture—one where CPU bottlenecks are caught, understood, and resolved before they ever surface as user‑visible latency.

Just Got Posted

Fresh from the Writer

People Also Read

Related Reading

Thank you for reading about How To Check Cpu In Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home