I think CPU cores are best-explained in relation to Symmetric MultiProcessing (SMP).

Intel Core 2 Duo Diagram to show the physical layout.

The system's CPU info is stored in the /proc
directory. It can be neatly presented by the lscpu
software, as below. I'm giving a three examples for contrast: a desktop with 2 CPU cores, a server with 48, and a Raspberry Pi with 4.
Desktop Computer
user@hostname:~$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 2
On-line CPU(s) list: 0,1
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 60
Stepping: 3
CPU MHz: 800.000
BogoMIPS: 5586.94
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 2048K
NUMA node0 CPU(s): 0,1
Server
user@hostname% lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 48
On-line CPU(s) list: 0-47
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 62
Stepping: 4
CPU MHz: 1799.724
BogoMIPS: 3600.09
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 30720K
NUMA node0 CPU(s): 0-47
Raspberry Pi
jeff@clear-pi:~ $ lscpu
Architecture: armv7l
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 4
Socket(s): 1
Model name: ARMv7 Processor rev 5 (v7l)
CPU max MHz: 900.0000
CPU min MHz: 600.0000
The server total is 48, but there are 3 numbers that must be multiplied to get there: 2*12*2=48. CPU manufacturer arrangement differences are apparent when comparing this way.
Desktop
[Thread(s) per core: 1] * [Core(s) per socket: 1] * [Socket(s): 1] = 2
Server
[Thread(s) per core: 2] * [Core(s) per socket: 12] * [Socket(s): 2] = 48
Raspberry Pi
[Thread(s) per core: 1] * [Core(s) per socket: 4] * [Socket(s): 1] = 4
lshw
has more system info, but not quite as helpful here.
Desktop Computer
user@hostname:~$ sudo lshw
*-cpu
description: CPU
product: Intel(R) Celeron(R) CPU G1840 @ 2.80GHz
vendor: Intel Corp.
physical id: 9
bus info: cpu@0
version: Intel(R) Celeron(R) CPU G1840 @ 2.80GHz
slot: SOCKET 0
size: 2800MHz
capacity: 3800MHz
width: 64 bits
clock: 100MHz
Server
user@hostname% sudo lshw
*-cpu:0
description: CPU
product: Intel(R) Xeon(R) CPU E5-2651 v2 @ 1.80GHz
vendor: Intel Corp.
physical id: 4
bus info: cpu@0
version: Intel(R) Xeon(R) CPU E5-2651 v2 @ 1.80GHz
slot: SOCKET 0
size: 1800MHz
capacity: 4GHz
width: 64 bits
clock: 100MHz
Raspberry Pi
user@hostname:~ $ sudo lshw
*-cpu:0
description: CPU
product: cpu
physical id: 0
bus info: cpu@0
size: 900MHz
capacity: 900MHz
capabilities: cpufreq
Lastly, this method has worked for me across several different Linux/UNIX operating systems where lscpu was not available. It's a variation of something suggested in the question and comments, but I prefer the short-hand command and simple output.
user@hostname:~ $ grep -c ^processor /proc/cpuinfo
4
Reference: How to find the number of CPU cores including virtual?
Reference: https://stackoverflow.com/questions/6481005/how-to-obtain-the-number-of-cpus-cores-in-linux-from-the-command-line
Reference: https://stackoverflow.com/questions/19225859/difference-between-core-and-processor
/proc/cpuinfo
you can see to which physical core it belongs by looking at thecore id
field. You should therefore be able to get a count of the number of physical cores by runningcat /proc/cpuinfo |grep 'core id'|sort|uniq|wc -l
– lgpasquale May 28 '15 at 11:54/proc/cpuinfo
over anything else. Does this work:taskset -c 23 cat /dev/zero > /dev/null
, meaning can you force the use of cpu number 23? – Doug Smythies May 28 '15 at 14:29lscpu
give? – Doug Smythies May 28 '15 at 14:41lscpu: CPU(s): 24 On-line CPU(s) list: 0-23 Thread(s) per core: 2 Core(s) per socket: 12 Socket(s): 1
Also , I am currently running tasks that seems to be using 24 cpus. So all is well with that. But I still do not get why the System tells me 16.. ah well
– dmeu May 29 '15 at 07:54