Top 8 lệnh kiểm tra thông tin CPU trên Linux

Top 8 lệnh kiểm tra thông tin CPU trên Linux – Trong bài hướng dẫn này Cuongquach.com sẽ hướng dẫn các bạn 8 cách khác nhau để trích xuất thông tin chi tiết về CPU trên máy chủ vật lý, VPS hay server của bạn sử dụng OS dạng *UNIX/Linux. Không chỉ cung cấp cho bạn cái nhìn tổng quan về CPU, mình sẽ tìm kiếm thông tin khác như kiến trúc CPU, vendor_id, model, model name, số core CPU, tốc độ mỗi core… về cơ bản thì thông tin CPU đều nằm trong /proc/cpuinfo, tùy theo mỗi lệnh Linux hoặc tiện ích mà lấy kết quả output khác nhau từ file này thôi.

top 8 lệnh kiểm tra thông tin cpu trên linux

Có thể bạn cũng quan tâm chủ đề khác:
Hướng dẫn tìm thông tin serial number của server trên Linux
Hiển thị file và thư mục ẩn trên Linux
Tìm tên driver card NIC và version driver NIC trên Linux
Khởi động lại Linux như thế nào ?
Top 11 mẹo sử dụng lệnh Linux mà bạn nên biết

Top 8 lệnh kiểm tra thông tin CPU trên Linux

1. File /proc/cpuinfo

Bạn có thể đơn giản hóa việc xem thông tin CPU hệ thống của bạn bằng cách đọc file /proc/cpuinfo với lệnh cat.

# cat /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 44
model name	: Intel(R) Xeon(R) CPU           L5639  @ 2.13GHz
stepping	: 2
cpu MHz		: 2133.408
cache size	: 12288 KB
physical id	: 0
siblings	: 1
core id		: 0
cpu cores	: 1
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 11
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc up arch_perfmon nonstop_tsc unfair_spinlock pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt aes hypervisor lahf_lm ida arat
bogomips	: 4266.81
clflush size	: 64
cache_alignment	: 64
address sizes	: 36 bits physical, 48 bits virtual
power management:

Để lấy các thông tin cụ thể hơn bạn có thể sử lệnh grep – một công cụ CLI dùng để tìm kiếm dữ liệu dạng plain-text cho mỗi dòng trùng với biểu thức chính quy đưa ra. Điều này giúp bạn lấy ra thông tin cuart vendor name, model name, số lượng processors, số lượng core

# cat /proc/cpuinfo | grep 'vendor' | uniq
# cat /proc/cpuinfo | grep 'model name' | uniq
# cat /proc/cpuinfo | grep processor | wc -l
# cat /proc/cpuinfo | grep 'core id'

2. Lệnh lscpu – hiển thị thông tin kiến trúc CPU

Lệnh này sẽ in ra thông tin kiến trúc CPU từ sysfs/proc/cpuinfo .

# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 44
Model name:            Intel(R) Xeon(R) CPU           L5639  @ 2.13GHz
Stepping:              2
CPU MHz:               2133.408
BogoMIPS:              4266.81
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              12288K
NUMA node0 CPU(s):     0

3. Lệnh cpuid – hiển thị x86 CPU

Lệnh này sẽ lấy thông tin đầy đủ về (những) CPU thu thập được từ chỉ thị CPUID và đưa ra mô hình chính xác của x86 CPU từ những thông tin đó.

Cài đặt:

# sudo apt install cpuid #Debian/Ubuntu systems
# sudo yum install cpuid #RHEL/CentOS systems 
# sudo dnf install cpuid #Fedora 22+

Sử dụng:

# cpuid

CPU 0:
   vendor_id = "GenuineIntel"
   version information (1/eax):
      processor type  = primary processor (0)
      family          = Intel Pentium Pro/II/III/Celeron/Core/Core 2/Atom, AMD Athlon/Duron, Cyrix M2, VIA C3 (6)
      model           = 0xd (13)
      stepping id     = 0x7 (7)
      extended family = 0x0 (0)
      extended model  = 0x2 (2)
      (simple synth)  = Intel Core i7-3800/3900 (Sandy Bridge-E C2) / Xeon E5-1600/2600/4600 (Sandy Bridge-E C2/M1), 32nm
   miscellaneous (1/ebx):
      process local APIC physical ID = 0x0 (0)
      cpu count                      = 0x0 (0)
      CLFLUSH line size              = 0x8 (8)
      brand index                    = 0x0 (0)
   brand id = 0x00 (0): unknown
   feature information (1/edx):
      x87 FPU on chip                        = true
      virtual-8086 mode enhancement          = true
      debugging extensions                   = true
      page size extensions                   = true
      time stamp counter                     = true
      RDMSR and WRMSR support                = true
      physical address extensions            = true
      machine check exception                = true
      CMPXCHG8B inst.                        = true
      APIC on chip                           = true
      SYSENTER and SYSEXIT                   = true
      memory type range registers            = true
      PTE global bit                         = true
      machine check architecture             = true
      conditional move/compare instruction   = true
      page attribute table                   = true
      page size extension                    = true
      processor serial number                = false
      CLFLUSH instruction                    = true
      debug store                            = false
      thermal monitor and clock ctrl         = false
      MMX Technology                         = true
      FXSAVE/FXRSTOR                         = true
      SSE extensions                         = true
      SSE2 extensions                        = true
      self snoop                             = true
      hyper-threading / multi-core supported = false
      therm. monitor                         = false
      IA64                                   = false
      pending break event                    = false
….

4. Lệnh dmidecode – Hiển thị thông tin phần cứng Linux

Công cụ dmidecode có thể lấy thông tin phần cứng trên bất kỳ OS Linux nào. Nó lấy nội dung bảng DMI (a.k.a SMBIOS) trích xuất ra định dạng mà chúng ta dễ dàng đọc. SMBIOS định nghĩa các loại DMI khác nhau, với việc tìm kiếm thông tin COU thì sử dụng option “processor” như bên dưới.

# dmidecode --type processor
# dmidecode 2.12
SMBIOS 2.7 present.

Handle 0x0004, DMI type 4, 35 bytes
Processor Information
	Socket Designation: CPU Socket #0
	Type: Central Processor
	Family: Xeon MP
	Manufacturer: GenuineIntel
	ID: C2 06 02 00 FF FB EB BF
	Signature: Type 0, Family 6, Model 44, Stepping 2
	Flags:
		FPU (Floating-point unit on-chip)
		VME (Virtual mode extension)
		DE (Debugging extension)
		PSE (Page size extension)
		TSC (Time stamp counter)
		MSR (Model specific registers)
		PAE (Physical address extension)
		MCE (Machine check exception)
		CX8 (CMPXCHG8 instruction supported)
		APIC (On-chip APIC hardware supported)
		SEP (Fast system call)
		MTRR (Memory type range registers)
		PGE (Page global enable)
		MCA (Machine check architecture)
		CMOV (Conditional move instruction supported)
		PAT (Page attribute table)
		PSE-36 (36-bit page size extension)
		CLFSH (CLFLUSH instruction supported)
		DS (Debug store)
		ACPI (ACPI supported)
		MMX (MMX technology supported)
		FXSR (FXSAVE and FXSTOR instructions supported)
		SSE (Streaming SIMD extensions)
		SSE2 (Streaming SIMD extensions 2)
		SS (Self-snoop)
		HTT (Multi-threading)
		TM (Thermal monitor supported)
		PBE (Pending break enabled)
	Version: Not Specified
	Voltage: 3.3 V
	External Clock: 355 MHz
	Max Speed: 2133 MHz
	Current Speed: 2133 MHz
	Status: Populated, Enabled
	Upgrade: Other
	L1 Cache Handle: Not Provided
	L2 Cache Handle: Not Provided
	L3 Cache Handle: Not Provided
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified

5. Công cụ Inxi – Hiển thị thông tin hệ thống Linux

Inxi là một script sử dụng CLI mạnh mẽ dành cho cả console và IRC (Internet Relay Chat). Để sử dụng bạn cần cài đặt như sau:

# sudo apt install inxi #Debian/Ubuntu systems
# sudo yum install inxi #RHEL/CentOS systems 
# sudo dnf install inxi #Fedora 22+

Để hiển thị thông tin CPU đầy đủ bao gồm mỗi tốc độ xung nhịp và tốc độ CPU tối đa (nếu có) bạn sử dụng option -C như sau:

# inxi -C
CPU(s):    2 6 core Intel Xeon E5-2620 v3s (-MT-MCP-SMP-) cache: 30720 KB
           clock speeds: max: 2399 MHz 1: 2399 MHz 2: 2399 MHz 3: 2399 MHz 4: 2399 MHz 5: 2399 MHz 6: 2399 MHz
           7: 2399 MHz 8: 2399 MHz 9: 2399 MHz 10: 2399 MHz 11: 2399 MHz 12: 2399 MHz 13: 2399 MHz 14: 2399 MHz
           15: 2399 MHz 16: 2399 MHz 17: 2399 MHz 18: 2399 MHz 19: 2399 MHz 20: 2399 MHz 21: 2399 MHz
           22: 2399 MHz 23: 2399 MHz 24: 2399 MHz

6. Công cụ lshw – List Hardware Configuration

lshw là công cụ đơn giản để thu thập thông tin về phần cứng của máy tính. Bạn có thể sử dụng option -C CPU để chọn lớp phần cứng CPU trong trường hợp này.

# lshw -C CPU
  *-cpu:0
       description: CPU
       product: Xeon
       vendor: Intel Corp.
       vendor_id: GenuineIntel
       physical id: 400
       bus info: cpu@0
       version: Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
       slot: CPU1
       size: 2400MHz
       capacity: 4GHz
       width: 64 bits
       clock: 3705MHz
       capabilities: x86-64 fpu fpu_exception wp 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 constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm cqm_llc cqm_occup_llc
       configuration: cores=6 enabledcores=6 threads=12

7. hwinfo

hwinfo được sử dụng để trích xuất thông tin phần cứng hiện tại, để hiển thị thông tin CPU ta sử dụng lệnh sau:

# hwinfo --cpu

8. nproc – hiển thị số lượng processors

Lệnh nproc để hiển thị số đơn vị processor trong máy tính của bạn, sử dụng như sau:

# nproc
24

Bài viết của mình đến đây là hết rồi, hy vọng với post này sẽ giúp ích các bạn trong việc sử dụng lệnh xác định thông tin CPU của VPS, server Linux của các bạn. Cám ơn các bạn đã theo dõi nhé.

Nguồnhttps://cuongquach.com

Previous article[AWS] Hướng dẫn tạo EC2 Instance Amazon Linux hoặc Windows
Next articleLỗ hổng Meltdown và Spectre ảnh hưởng hàng loạt thiết bị điện tử thế giới
Bạn đang theo dõi website "https://cuongquach.com/" nơi lưu trữ những kiến thức tổng hợp và chia sẻ cá nhân về Quản Trị Hệ Thống Dịch Vụ & Mạng, được xây dựng lại dưới nền tảng kinh nghiệm của bản thân mình, Quách Chí Cường. Hy vọng bạn sẽ thích nơi này !