How to find the number of CPU cores including virtual?
Solution 1
You can count no of CPUs
cat /proc/cpuinfo | grep processor | wc -l
Output :
2
To check the number of cores !
cat /proc/cpuinfo | grep 'core id'
core id : 0
core id : 1
Or
$ nproc
2
Or lscpu will show you all output:
lscpu
Architecture: i686
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
Vendor ID: GenuineIntel
CPU family: 15
Model: 4
Stepping: 7
CPU MHz: 2792.992
BogoMIPS: 5585.98
L1d cache: 16K
L2 cache: 1024K
Solution 2
To add to the existing answers, you can determine information about Intel's HyperThreading by looking at the "siblings" line in /proc/cpuinfo. The example below is from a 2 socket machine. It shows the CPU has 6 cores but 12 "siblings". On Intel CPUs this means HyperThreading is enabled and there are 6 physical cores.
processor : 23
vendor_id : GenuineIntel
cpu family : 6
model : 62
model name : Intel(R) Xeon(R) CPU E5-2430 v2 @ 2.50GHz
stepping : 4
microcode : 0x428
cpu MHz : 1599.707
cache size : 15360 KB
physical id : 1
siblings : 12
core id : 5
cpu cores : 6
apicid : 43
initial apicid : 43
fpu : yes
fpu_exception : yes
cpuid level : 13
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 arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 5005.20
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
dmidecode is also useful for determining what hardware a Linux system is running on.
Solution 3
/proc/cpuinfo
contains all the CPUs for my computer, including virtual. You can count them with a little grep
:
grep -Pc '^processor\t' /proc/cpuinfo
Solution 4
You can also install htop
(a fancier version of top
) which will show you all your cores.
sudo apt-get install htop
Then start it: htop
Solution 5
Assuming you don't turn off your cores/threads, this command will answer your question:
getconf _NPROCESSORS_ONLN
Related videos on Youtube
Hasan-Almujtaba
Updated on September 18, 2022Comments
-
Hasan-Almujtaba over 1 year
I would like to create something similiar like tesla.com, content on left side will change when right side is scrolled.
I have tried create it using vuetify intersection, but it still buggy. Is there some way to improve it?
Here is demo for code i already created : https://hyundai-andalan.vercel.app/models/staria
This is code i using:
// page component <template> <div> <ModelDesktop v-if="$vuetify.breakpoint.lgAndUp" /> <ModelMobile v-else /> </div> </template> <script> import model from '~/mixins/model' export default { mixins: [model], head () { return { title: this.model.name } } } </script>
// model desktop component <template> <div class="tw-grid tw-grid-cols-3"> <div class="tw-col-span-2"> <ModelCarousel :section="section" class="tw-sticky tw-top-0" /> </div> <ModelDesktopContentWrapper @change:section="onSectionChange" /> </div> </template> <script> export default { data () { return { section: 'exterior' } }, methods: { onSectionChange (value) { this.section = value } } } </script>
// model carousel component <template> <v-carousel v-model="carousel" height="100vh"> <v-carousel-item v-for="(item, i) in model[section].collection" :key="i" > <v-img :src="item.image" aspect-ratio="1" eager /> </v-carousel-item> </v-carousel> </template> <script> import model from '~/mixins/model' export default { mixins: [model], props: { section: { type: String, default: 'exterior' } }, data: () => ({ carousel: 0, colors: [ 'primary', 'secondary', 'yellow darken-2', 'red', 'orange' ] }) } </script>
// model desktop component wrapper <template> <div class="tw-p-16"> <!-- Specification & Content --> <div v-intersect="onExterior"> <ModelSpecification /> <ModelContent section="exterior" v-bind="model.exterior" /> </div> <!-- Specification & Content --> <!-- Interior --> <ModelContent v-intersect="onInterior" section="interior" v-bind="model.interior" /> <!-- Interior --> <!-- Interior --> <ModelContent v-intersect="onPerformance" section="performance" v-bind="model.performance" /> <!-- Interior --> <!-- Interior --> <ModelContent v-intersect="onSafety" section="safety" v-bind="model.safety" /> <!-- Interior --> </div> </template> <script> import model from '~/mixins/model' export default { mixins: [model], data () { return { exterior: false, interior: false, performance: false, safety: false } }, watch: { exterior (newValue) { if (newValue) { this.interior = false this.performance = false this.safety = false this.$emit('change:section', 'exterior') } }, interior (newValue) { if (newValue) { this.exterior = false this.performance = false this.safety = false this.$emit('change:section', 'interior') } }, performance (newValue) { if (newValue) { this.exterior = false this.interior = false this.safety = false this.$emit('change:section', 'performance') } }, safety (newValue) { if (newValue) { this.exterior = false this.interior = false this.performance = false this.$emit('change:section', 'safety') } } }, methods: { onExterior (entries) { this.exterior = entries[0].isIntersecting }, onInterior (entries) { this.interior = entries[0].isIntersecting }, onPerformance (entries) { this.performance = entries[0].isIntersecting }, onSafety (entries) { this.safety = entries[0].isIntersecting } } } </script>
// model content component <template> <div> <!-- Main Content --> <div class="lg:tw-h-screen lg:tw-flex lg:tw-items-center tw-w-full"> <div class="lg:tw-flex-1"> <div class="tw-text-center"> <v-img v-if="$vuetify.breakpoint.mdAndDown" :src="banner" class="tw-mb-2" /> <h2 class="tw-capitalize"> {{ section }} </h2> <h3 class="tw-font-medium"> {{ title }} </h3> <div class="tw-mb-5" v-text="description" /> <v-btn rounded @click="dialogOpen = true"> feature detail </v-btn> </div> </div> </div> <!-- Main Content --> <ModelContentDialog v-model="dialogOpen" :section="section" :collection="collection" /> </div> </template> <script> export default { props: { section: { type: String, required: true }, title: { type: String, required: true }, description: { type: String, required: true }, banner: { type: String, default: '' }, collection: { type: Array, required: true } }, data () { return { dialogOpen: false } } } </script>
-
heemayl over 8 yearsThis will show the number of cores Online which can be different from the total number of cores..
-
Iluvathar over 8 years@heemayl that's why I started the answer as I did.
-
Iluvathar over 8 years
grep
can count matches with-c
option, no need inwc
. -
heemayl over 8 yearsmakes sense..i have overlooked that.. +1
-
arun over 6 yearsi.e. the first command is equivalent to
grep -c processor /proc/cpuinfo
-
kaushalpranav almost 6 yearsThis gives the number of CPUs, not the number of cores.
-
Farway over 5 years
nproc
is also useful in scripts depending on the number of cores available to it. E.g.make -j$(nproc)
. -
Gabriel Staples over 4 years+1 for including
lscpu
in your answer, which is by far the easiest command to use. -
seralouk over 4 yearshow to check this for a specific user?
-
Aditya about 4 yearshow to display only one of those two 'core id's?