Linux CPU Number Judgment command

Source: Internet
Author: User
Tags socket

In fact, as long as

#include <unistd.h>
Long num = sysconf (_SC_NPROCESSORS_ONLN);

You can get the current number of CPUs ...

Judge the basis:
1. CPUs with the same core ID are the same core hyper-threading.
2. CPUs with the same physical ID are the same CPU-encapsulated threads or cores.

English version:
1.Physical ID and core ID are not necessarily consecutive but they unique. Any CPUs with the same core ID are hyperthreads in the same core.
2.Any CPU with the same physical ID are threads or cores in the same socket.

Instance:

CPU Information for Lunarpages:

processor:0
Vendor_id:genuineintel
CPU Family:15
Model:4
Model Name:intel (R) Xeon (TM) CPU 3.00GHz
Stepping:3
CPU mhz:3000.881
Cache size:2048 KB
Physical id:0
Siblings:2
Core id:0
CPU Cores:1
Fdiv_bug:no
Hlt_bug:no
F00f_bug:no
Coma_bug:no
Fpu:yes
Fpu_exception:yes
CPUID Level:5
Wp:yes
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC MTRR PGE MCA cmov Pat PSE36 clflush DTS ACPI MMX FXSR SSE SSE2 SS HT TM PB E lm constant_tsc PNI monitor ds_cpl CID XTPR
bogomips:6006.73

Processor:1
Vendor_id:genuineintel
CPU Family:15
Model:4
Model Name:intel (R) Xeon (TM) CPU 3.00GHz
Stepping:3
CPU mhz:3000.881
Cache size:2048 KB
Physical id:0
Siblings:2
Core id:0
CPU Cores:1
Fdiv_bug:no
Hlt_bug:no
F00f_bug:no
Coma_bug:no
Fpu:yes
Fpu_exception:yes
CPUID Level:5
Wp:yes
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC MTRR PGE MCA cmov Pat PSE36 clflush DTS ACPI MMX FXSR SSE SSE2 SS HT TM PB E lm constant_tsc PNI monitor ds_cpl CID XTPR
bogomips:5999.40

Processor:2
Vendor_id:genuineintel
CPU Family:15
Model:4
Model Name:intel (R) Xeon (TM) CPU 3.00GHz
Stepping:3
CPU mhz:3000.881
Cache size:2048 KB
Physical Id:3
Siblings:2
Core Id:3
CPU Cores:1
Fdiv_bug:no
Hlt_bug:no
F00f_bug:no
Coma_bug:no
Fpu:yes
Fpu_exception:yes
CPUID Level:5
Wp:yes
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC MTRR PGE MCA cmov Pat PSE36 clflush DTS ACPI MMX FXSR SSE SSE2 SS HT TM PB E lm constant_tsc PNI monitor ds_cpl CID XTPR
bogomips:5999.08

Processor:3
Vendor_id:genuineintel
CPU Family:15
Model:4
Model Name:intel (R) Xeon (TM) CPU 3.00GHz
Stepping:3
CPU mhz:3000.881
Cache size:2048 KB
Physical Id:3
Siblings:2
Core Id:3
CPU Cores:1
Fdiv_bug:no
Hlt_bug:no
F00f_bug:no
Coma_bug:no
Fpu:yes
Fpu_exception:yes
CPUID Level:5
Wp:yes
FLAGS:FPU VME de PSE TSC MSR PAE MCE cx8 APIC MTRR PGE MCA cmov Pat PSE36 clflush DTS ACPI MMX FXSR SSE SSE2 SS HT TM PB E lm constant_tsc PNI monitor ds_cpl CID XTPR
bogomips:5999.55

Displays 4 logical CPUs, the same as the previous two logical CPUs through the physical ID, followed by two, so there are two physical CPUs. The previous two core IDs are the same, followed by the same two core IDs, indicating that all two CPUs are single cores. That is to say, two single core CPUs enabled Hyper-Threading technology.
The Intel CPU parameters can be initially judged using two Xeon Pentium 4CPU, a bit poor ....
How to obtain the CPU details:

Linux command:

#cat/proc/cpuinfo

Using commands to determine several physical CPUs, several cores, etc.:

Number of logical CPUs:
# Cat/proc/cpuinfo | grep ' Processor ' | Wc-l

Number of physical CPUs:
# Cat/proc/cpuinfo | grep ' Physical ID ' | Sort | Uniq | Wc-l

Number of core in each physical CPU:
# Cat/proc/cpuinfo | grep ' CPU cores ' | Wc-l

Is it a hyper-threading?
If there are two logical CPUs with the same "core ID", then the Hyper-threading is turned on.

The number of logical CPUs (possibly core, threads, or both) per physical CPU:
# Cat/proc/cpuinfo | grep ' siblings '
Other Features:

At present, Intel's new multi-core CPUs will display specific model numbers later, such as:

Model Name:intel (R) Xeon (r) CPU X3230 @ 2.66GHz

Description is the CPU of the Xeon 3230, and does not show the specific number of models, most of them are Pentium CPU

Many host dealers cheat, with the Pentium CPU, but said to be the core of the CPU.

Probe to see the data:

Type: Intel (R) Xeon (TM) CPU 2.80GHz cache: 1024 KB
Type: Intel (R) Xeon (TM) CPU 2.80GHz cache: 1024 KB
Type: Intel (R) Xeon (TM) CPU 2.80GHz cache: 1024 KB
Type: Intel (R) Xeon (TM) CPU 2.80GHz cache: 1024 KB

No specific models, cache 1M, are generally Pentium series of CPUs, or Intel fake dual-core CPU, specifically according to the above to judge. The new multi-core CPU can see the specific model.
Other Xeon CPU, the general frequency is not high, reached 2.8 and 3.0 of only a few high-end CPU models, the general host will not be used so well.


The latest versions of some operating systems have updated the/proc/cpuinfo files to support multiple platforms. If the/proc/cpuinfo files in your system correctly reflect processor information, you do not need to perform the above steps. Conversely, the information in this article can be used to explain.

The/proc/cpuinfo file contains a paragraph of data for each processor on the system. The/proc/cpuinfo description contains 6 entries for multi-core and Hyper-Threading (HT) Technical checks: processor, vendor ID, physical ID, siblings, core ID, and CPU cores.

The processor entry includes a unique identifier for this logical processor.
The physical ID entry includes a unique identifier for each physical package.
The core ID entry holds a unique identifier for each kernel.
The siblings entry lists the number of logical processors in the same physical package.
The CPU cores entry contains the number of cores in the same physical package.

If the processor is an Intel processor, the string in the vendor ID entry is Genuineintel.

1. All logical processors with the same physical ID share the same physical socket. Each physical ID represents a unique physical package.

2.Siblings represents the number of logical processors located on this physical package. They may or may not support Hyper-Threading (HT) technology.

3. Each core ID represents a unique processor kernel. All logical processors with the same core ID are located on the same processor core.

4. If more than one logical processor has the same core ID and physical ID, the system supports Hyper-threading (HT) technology.

5. If there are two or more logical processors with the same physical ID, but the core ID is different, this is a multi-core processor. CPU cores entries can also indicate whether multiple cores are supported.

For example, if your system contains two physical wrappers, and each package contains two processor cores that support Hyper-Threading (HT) technology, the/proc/cpuinfo file will contain this data.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.