Skip to content

How to Check the CPU Count in Linux: Cores, Threads, Sockets

Updated 5 min read

Updated: 18 October 2026 · Applies to: Debian 13 (coreutils 9.7, util-linux 2.41), AlmaLinux 10.2 (coreutils 9.5), Ubuntu 26.04 (uutils nproc 0.10.0) on a KVM VPS, tested

The quickest way to count CPUs in Linux is nproc: it prints the number of CPUs your programs can use. For the full picture, run lscpu and read four lines: CPU(s), Thread(s) per core, Core(s) per socket and Socket(s). The CPU count Linux shows is always:

CPU(s) = Socket(s) x Core(s) per socket x Thread(s) per core
nproc                                # CPUs available to this shell
nproc --all                          # all installed CPUs
lscpu                                # sockets, cores, threads, model
grep -c ^processor /proc/cpuinfo     # count of logical CPUs

1. Count CPUs with nproc, getconf and /proc/cpuinfo

Lab example from a small KVM VPS with one vCPU (Debian 13 inside it; AlmaLinux 10.2 and Ubuntu 26.04 gave the same numbers):

$ nproc
1
$ nproc --all
1
$ getconf _NPROCESSORS_ONLN
1
$ grep -c ^processor /proc/cpuinfo
1

All four count logical CPUs: on a server with Hyper-Threading or SMT, every hardware thread counts as one CPU. On a VPS, every vCPU counts as one CPU. On Ubuntu 26.04, nproc comes from the Rust uutils coreutils (0.10.0) and gave the same results as GNU nproc.

2. Read lscpu on a KVM VPS

Lab example from the same VPS, shortened (the Flags and Vulnerability lines are left out):

$ lscpu
Architecture:             x86_64
CPU(s):                   1
On-line CPU(s) list:      0
Vendor ID:                AuthenticAMD
Model name:               AMD EPYC 7551 32-Core Processor
Thread(s) per core:       1
Core(s) per socket:       1
Socket(s):                1
Hypervisor vendor:        KVM
Virtualization type:      full
L3 cache:                 64 MiB (1 instance)
NUMA node(s):             1
  • CPU(s): 1 is what this machine can use.
  • Model name is the physical processor of the host. "32-Core" describes that chip, not your VPS.
  • Hypervisor vendor: KVM tells you that you are inside a virtual machine. On a physical (dedicated) server this line is normally absent.

The lscpu manual warns that in a virtual machine the topology "reflects the configuration of the guest operating system", and that on virtual hardware the number of cores per socket "can be wrong". On a VPS, trust CPU(s); the split into sockets and cores is just how the hypervisor presents the vCPUs.

If lscpu is missing (the AlmaLinux 10 container image has only util-linux-core), install it with dnf install util-linux. Debian and Ubuntu include it by default.

3. Sockets, cores and threads explained

  • Socket: a physical processor package on the motherboard. Most servers have one or two.
  • Core: an independent processing unit inside the processor.
  • Thread: with Hyper-Threading (Intel) or SMT (AMD), each core usually runs two threads. Linux shows each thread as a CPU.

To show a server with all three, we booted a test virtual machine with 2 sockets, 2 cores per socket and 2 threads per core (QEMU with util-linux 2.42 inside, lab example):

$ lscpu | grep -E '^(CPU\(s\)|Thread|Core|Socket)'
CPU(s):                   8
Thread(s) per core:       2
Core(s) per socket:       2
Socket(s):                2
$ lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE
  0    0      0    0 0:0:0:3          yes
  1    0      0    0 1:1:1:3          yes
  2    0      0    1 2:2:2:3          yes
  3    0      0    1 3:3:3:3          yes
  4    0      1    2 4:4:4:4          yes
  5    0      1    2 5:5:5:4          yes
  6    0      1    3 6:6:6:4          yes
  7    0      1    3 7:7:7:4          yes

2 x 2 x 2 = 8 CPUs. CPUs 0 and 1 share core 0, so they are two threads of one physical core. In /proc/cpuinfo the same layout shows as physical id (the socket), core id, cpu cores (cores per socket, here 2) and siblings (threads per socket, here 4).

4. Count physical sockets and cores

Run on the same test machine:

$ grep 'physical id' /proc/cpuinfo | sort -u | wc -l      # sockets
2
$ lscpu -p=Socket,Core | grep -v '^#' | sort -u | wc -l  # physical cores
4
$ grep -c ^processor /proc/cpuinfo                       # threads (logical CPUs)
8

Some software licences are counted per physical core or per socket, so these numbers can matter as much as the logical count. More on sockets: how to find the number of CPU sockets.

5. Why nproc can show fewer CPUs than the server has

nproc counts the CPUs available to the current process. nproc --all counts all installed CPUs. Tested with Debian's GNU nproc 9.7 on the 8-CPU test machine:

$ taskset -c 0,1 nproc                 # process pinned to CPUs 0 and 1
2
$ echo 0 > /sys/devices/system/cpu/cpu7/online   # take CPU 7 offline
$ nproc; nproc --all
7
8
$ getconf _NPROCESSORS_ONLN; getconf _NPROCESSORS_CONF
7
8

After taking a CPU offline, lscpu adds the line Off-line CPU(s) list: 7. To enable or disable CPUs on purpose, see how to enable or disable CPUs.

One more trap: nproc obeys the OpenMP variable OMP_NUM_THREADS. On the one-vCPU VPS, OMP_NUM_THREADS=4 nproc printed 4 with GNU coreutils 9.5 and 9.7 and with uutils 0.10.0. According to the nproc manual, --all ignores OpenMP variables and CPU quotas.

6. Use the CPU count in scripts

  1. Build with one job per CPU: make -j"$(nproc)".
  2. Leave one CPU free for the system: nproc --ignore=1. The result is never below 1 (it printed 1 on the one-vCPU VPS).
  3. For a value that other tools can parse, use lscpu -J (JSON) or lscpu -p (comma-separated).

Related guides: how to find the CPU frequency in Linux and how to check CPU usage with top, htop, mpstat and sar. If your workload needs more cores, a KVM VPS shows its vCPUs exactly as above, and a dedicated server gives you the physical sockets and cores.

Official documentation: lscpu(1) and nproc(1).

Was this answer helpful?

Still stuck? Open a ticket