Home >Operation and Maintenance >Linux Operation and Maintenance >How to get CPU information in Linux?

How to get CPU information in Linux?

青灯夜游
青灯夜游Original
2019-04-10 10:22:569441browse

The CPU (Central Processing Unit), often referred to simply as the processor, is one of the most important components of a machine; it performs all types of data processing operations and is considered the brain of the computer. What if we want to view CPU information (such as processor type and speed)? The following article will introduce to you how to obtain and view CPU information from the command line in Linux. I hope it will be helpful to you.

How to get CPU information in Linux?

Method 1: View the /proc/cpuinfo file to obtain CPU information

By displaying /proc The content of the /cpuinfo virtual file is the easiest way to determine information such as the CPU type. Using the proc/cpuinfo file to identify the processor type does not require the installation of any other programs. It works no matter what Linux distribution we are using.

Open the terminal and use less or cat to display the contents of /proc/cpuinfo so that we can obtain and view the CPU information:

less /proc/cpuinfo

This command will display each logical CPU using the identification number. For example, if the computer has an 8-core processor, we will see a list of all cores starting from 0 to 7. The following is an example of the output:

processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
stepping	: 10
microcode	: 0x96
cpu MHz		: 700.120
cache size	: 6144 KB
physical id	: 0
siblings	: 8
core id		: 0
cpu cores	: 4
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips	: 3600.00
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

...

The following is an introduction to the important lines:

●Processor: The unique identification number of each processor, starting from 0.

● Model name: The full name of the processor, including the processor brand. Once we know the exact type of CPU we have, we can look at the product documentation for the processor specifications.

● Flags: CPU function.

If you don’t want to display so much information, you can use the grep command to filter the output. For example:

To display only the processor name that will be used:

grep -m 1 'model name' /proc/cpuinfo

Output:

model name: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz

To print the number of CPUs:

grep -c 'model name' /proc/cpuinfo

Output

8

Knowing the number of CPUs can be handy when compiling software from source code and you want to know how many parallel processes can be executed simultaneously. Another way to find the number of CPUs is to use the following nproc command:

nproc

output

8

Method Two: Use lscpu to get CPU information

lscpu is a command line utility used to display information about the CPU architecture. lscpu is part of the util-linux package and is installed on all Linux distributions.

At the shell prompt, type lscpu:

lscpu

The output will look like below, including information about CPU number, architecture, vendor, series, model, speed, cache, flags etc. information.

Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              8
On-line CPU(s) list: 0-7
Thread(s) per core:  2
Core(s) per socket:  4
Socket(s):           1
NUMA node(s):        1
Vendor ID:           GenuineIntel
CPU family:          6
Model:               142
Model name:          Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Stepping:            10
CPU MHz:             593.577
CPU max MHz:         3400.0000
CPU min MHz:         400.0000
BogoMIPS:            3600.00
Virtualization:      VT-x
L1d cache:           32K
L1i cache:           32K
L2 cache:            256K
L3 cache:            6144K
NUMA node0 CPU(s):   0-7
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp flush_l1d

Note: Unlike the contents of the /proc/cpuinfo file, the output of lscpu does not display a list of all logical CPUs.

Recommended related video tutorials: "Linux Tutorial"

The above is the entire content of this article, I hope it will be helpful to everyone's learning. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to get CPU information in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn