Shell實現識別物理cpu個數、核心數_linux shell

來源:互聯網
上載者:User

如何識別物理cpu個數,幾個核,是超執行緒還是多核心

判斷依據:

1.具有相同core id的cpu是同一個core的超執行緒。
2.具有相同physical id的cpu是同一顆cpu封裝的線程或者cores。

英文版:

1.Physical id and core id are not necessarily consecutive but they are unique. Any cpu 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 physical socket.

執行個體:

LunarPages的CPU資訊:

複製代碼 代碼如下:

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 pbe 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 pbe 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 pbe 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 pbe lm constant_tsc pni monitor ds_cpl cid xtpr
bogomips        : 5999.55

顯示4個邏輯CPU,通過physical id  ,前面兩個邏輯cpu的相同,後面兩個的相同,所以有兩個物理CPU。前面兩個的 core id相同,後面的兩個core ID相同,說明這兩個CPU都是單核。也就是說兩個單核cpu,啟用了超執行緒技術。

通過intel的cpu的參數可以初步判斷 使用的是兩個 Xeon奔騰4CPU ,有點差。。。。

如何獲得CPU的詳細資料:

linux命令:cat /proc/cpuinfo

用命令判斷幾個物理CPU,幾個核等:
邏輯CPU個數:

複製代碼 代碼如下:

# cat /proc/cpuinfo | grep “processor” | wc -l

物理CPU個數:
複製代碼 代碼如下:

# cat /proc/cpuinfo | grep “physical id” | sort | uniq | wc -l

每個物理CPU中Core的個數:
複製代碼 代碼如下:

# cat /proc/cpuinfo | grep “cpu cores” | wc -l

是否為超執行緒?

如果有兩個邏輯CPU具有相同的”core id”,那麼超執行緒是開啟的。
每個物理CPU中邏輯CPU(可能是core, threads或both)的個數:

複製代碼 代碼如下:

# cat /proc/cpuinfo | grep “siblings”

其他特徵:

目前intel新的多核心cpu都會在後面顯示具體的型號數字,例如:

複製代碼 代碼如下:

model name        : Intel(R) Xeon(R) CPU           X3230  @ 2.66GHz

說明是 Xeon 3230的cpu,而不顯示型號的具體數位,大部分都是奔騰的CPU
很多主機商都騙人,用奔騰的cpu,卻說是多核心的CPU。

探針看到的資料:

類型:Intel(R) Xeon(TM) CPU 2.80GHz 緩衝:1024 KB
類型:Intel(R) Xeon(TM) CPU 2.80GHz 緩衝:1024 KB
類型:Intel(R) Xeon(TM) CPU 2.80GHz 緩衝:1024 KB
類型:Intel(R) Xeon(TM) CPU 2.80GHz 緩衝:1024 KB

沒有具體的型號,緩衝1M,一般都是奔騰系列的cpu,或者是intel假雙核的cpu,具體要根據上面說的去判斷。新的多核心cpu都能看到具體的型號。

另外多核心的xeon的CPU,一般主頻都不高,達到2.8和3.0的只有很少的幾個高端CPU型號,一般主機商不會用這麼好的

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.