在Linux中,我们可以通过下面命令查看CPU信息

  1. lscpu
  2. cat /proc/cpuinfo
  3. top / htop
  4. nproc
  5. getconf _NPROCESSORS_ONLN

lscpu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
➜ lscpu                                   
Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   39 bits physical, 48 bits virtual
CPU(s):                          12
On-line CPU(s) list:             0-11
Thread(s) per core:              2
Core(s) per socket:              6
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       GenuineIntel
CPU family:                      6
Model:                           158
Model name:                      Intel(R) Core(TM) i7-9750H CPU @ 2

...

egrep过滤信息

1
2
3
4
5
6
7
8
➜ lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)'   
CPU(s):                          12
On-line CPU(s) list:             0-11
Thread(s) per core:              2
Socket(s):                       1
NUMA node(s):                    1
Model name:                      Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
NUMA node0 CPU(s):               0-11

parasable format

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
➜ lscpu -p
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting from zero.
# CPU,Core,Socket,Node,,L1d,L1i,L2,L3
0,0,0,0,,0,0,0,0
1,1,0,0,,1,1,1,0
2,2,0,0,,2,2,2,0
3,3,0,0,,3,3,3,0
4,4,0,0,,4,4,4,0
5,5,0,0,,5,5,5,0
6,0,0,0,,0,0,0,0
7,1,0,0,,1,1,1,0
8,2,0,0,,2,2,2,0
9,3,0,0,,3,3,3,0
10,4,0,0,,4,4,4,0
11,5,0,0,,5,5,5,0

/proc/cpuinfo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
➜ cat /proc/cpuinfo       
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 158
...

processor       : 1
vendor_id       : GenuineIntel
...

or

1
2
3
4
5
6
7
8
9
more /proc/cpuinfo
less /proc/cpuinfo

cat /proc/cpuinfo | grep 'vendor' | uniq		#view vendor name
cat /proc/cpuinfo | grep 'model name' | uniq		#display model name
cat /proc/cpuinfo | grep processor | wc -l		#count the number of processing units
cat /proc/cpuinfo | grep 'core id'			#show individual cores	
echo "CPU threads: $(grep -c processor /proc/cpuinfo)"
grep 'cpu cores' /proc/cpuinfo | uniq

top

执行top之后按’1'可以查看cpu信息

nproc

1
2
nproc --all
echo "Threads/core: $(nproc --all)"

getconf

1
2
➜ getconf _NPROCESSORS_CONF
12