CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / System Information / lscpu

lscpu

Show CPU architecture, cores, threads and caches

Beginnerhardwareperformancesystem info

lscpu summarises the CPUs the kernel sees: architecture, model, how many logical CPUs, cores per socket and threads per core, NUMA layout, caches and virtualisation. It answers 'how many cores does this box really have?' when you size worker pools, JVM threads or Kubernetes requests.

Syntaxlscpu [-e[=LIST]] [-p[=LIST]] [-J] [-y]

Watch it run

You're sizing a worker pool on a new VM and need to know what kind of CPU it has and how many.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
lscpu

CPU(s): 4 logical CPUs, made of 1 socket x 2 cores x 2 threads. So this '4 vCPU' VM has two physical cores, each with two hyperthreads. The hypervisor line confirms it's a VM.

Anatomy of a command

$
commandlscpu

util-linux lscpu: reads /proc/cpuinfo and /sys/devices/system/cpu and prints a summary.

How it works

lscpu doesn't probe the hardware itself. It reads what the kernel already discovered: /proc/cpuinfo for vendor, model, flags and BogoMIPS, and sysfs for topology: /sys/devices/system/cpu/cpuN/topology (core_id, package id, thread siblings), cache/indexN for cache sizes and sharing, online and possible CPU lists, and the NUMA node directories. It also runs the CPUID instruction to detect a hypervisor. Each 'CPU' in the CPU(s) line is a logical CPU, a hardware thread the scheduler can use; CPU(s) = sockets x cores per socket x threads per core. On cloud VMs a vCPU is usually one hyperthread, so 4 vCPUs are often 2 physical cores. In a container, lscpu and nproc show the host's CPUs; a CPU limit set with a cgroup quota is not visible here.

Options you'll actually use

(none)Human-readable summary
-eOne row per logical CPU: CPU, NODE, SOCKET, CORE, caches, ONLINE
-pParsable CSV-style output for scripts
-JJSON output
-CCache details: size, ways, level, sharing
-yShow physical IDs instead of logical ones
nprocCompanion: number of CPUs this process may use (affinity)
/proc/cpuinfoRaw per-CPU data that lscpu summarises

Common mistakes

Treating '4 vCPU' as 4 physical cores

On most cloud instances a vCPU is one hyperthread; two vCPUs share one core's execution units.

Check Thread(s) per core and Core(s) per socket in lscpu
Sizing a container's thread pool with nproc or lscpu inside it

A --cpus or Kubernetes CPU limit is a CFS quota, invisible to nproc and lscpu, which report the host's CPUs.

Read /sys/fs/cgroup/cpu.max, or set the pool size explicitly
Using BogoMIPS to compare CPU speed

BogoMIPS is a calibration loop for kernel delays, not a benchmark.

Compare model names and run a real benchmark of your workload

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Find how many logical CPUs, cores per socket and threads per core this machine has.

  2. 2

    Show one row per logical CPU with its core and socket.

  3. 3

    Compare nproc with the number of 'processor' entries in /proc/cpuinfo.

Related commands

unameShow the kernel name, version and architecturefreeShow used, free and available memorynumactlControl NUMA CPU and memory placementtopWatch CPU, memory and processes live
PrevioushostnameNextfree
Linux / System Information / lscpu

lscpu

Show CPU architecture, cores, threads and caches

Beginnerhardwareperformancesystem info

lscpu summarises the CPUs the kernel sees: architecture, model, how many logical CPUs, cores per socket and threads per core, NUMA layout, caches and virtualisation. It answers 'how many cores does this box really have?' when you size worker pools, JVM threads or Kubernetes requests.

Syntaxlscpu [-e[=LIST]] [-p[=LIST]] [-J] [-y]

Watch it run

You're sizing a worker pool on a new VM and need to know what kind of CPU it has and how many.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
lscpu

CPU(s): 4 logical CPUs, made of 1 socket x 2 cores x 2 threads. So this '4 vCPU' VM has two physical cores, each with two hyperthreads. The hypervisor line confirms it's a VM.

Anatomy of a command

$
commandlscpu

util-linux lscpu: reads /proc/cpuinfo and /sys/devices/system/cpu and prints a summary.

How it works

lscpu doesn't probe the hardware itself. It reads what the kernel already discovered: /proc/cpuinfo for vendor, model, flags and BogoMIPS, and sysfs for topology: /sys/devices/system/cpu/cpuN/topology (core_id, package id, thread siblings), cache/indexN for cache sizes and sharing, online and possible CPU lists, and the NUMA node directories. It also runs the CPUID instruction to detect a hypervisor. Each 'CPU' in the CPU(s) line is a logical CPU, a hardware thread the scheduler can use; CPU(s) = sockets x cores per socket x threads per core. On cloud VMs a vCPU is usually one hyperthread, so 4 vCPUs are often 2 physical cores. In a container, lscpu and nproc show the host's CPUs; a CPU limit set with a cgroup quota is not visible here.

Options you'll actually use

(none)Human-readable summary
-eOne row per logical CPU: CPU, NODE, SOCKET, CORE, caches, ONLINE
-pParsable CSV-style output for scripts
-JJSON output
-CCache details: size, ways, level, sharing
-yShow physical IDs instead of logical ones
nprocCompanion: number of CPUs this process may use (affinity)
/proc/cpuinfoRaw per-CPU data that lscpu summarises

Common mistakes

Treating '4 vCPU' as 4 physical cores

On most cloud instances a vCPU is one hyperthread; two vCPUs share one core's execution units.

Check Thread(s) per core and Core(s) per socket in lscpu
Sizing a container's thread pool with nproc or lscpu inside it

A --cpus or Kubernetes CPU limit is a CFS quota, invisible to nproc and lscpu, which report the host's CPUs.

Read /sys/fs/cgroup/cpu.max, or set the pool size explicitly
Using BogoMIPS to compare CPU speed

BogoMIPS is a calibration loop for kernel delays, not a benchmark.

Compare model names and run a real benchmark of your workload

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    Find how many logical CPUs, cores per socket and threads per core this machine has.

  2. 2

    Show one row per logical CPU with its core and socket.

  3. 3

    Compare nproc with the number of 'processor' entries in /proc/cpuinfo.

Related commands

unameShow the kernel name, version and architecturefreeShow used, free and available memorynumactlControl NUMA CPU and memory placementtopWatch CPU, memory and processes live
PrevioushostnameNextfree