How To Determine The Number of CPUs in Linux

  1. Simply use the lscpu command to view the number of CPUs
    # lscpu
    Architecture:        x86_64
    CPU op-mode(s):      32-bit, 64-bit
    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
    NUMA node(s):        1
    Vendor ID:           GenuineIntel
    CPU family:          6
    Model:               158
    Model name:          Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
    Stepping:            9
    CPU MHz:             2807.994
    BogoMIPS:            5615.98
    Hypervisor vendor:   KVM
    Virtualization type: full
    L1d cache:           32K
    L1i cache:           32K
    L2 cache:            256K
    L3 cache:            6144K
    NUMA node0 CPU(s):   0-3
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase avx2 invpcid rdseed clflushopt flush_l1d
  2. You can show the number of processing units with the nproc command
    # nproc --all
  3. Another option is to use the getconf command
    # getconf _NPROCESSORS_ONLN
  4. Finally, you can cat /proc/cpuinfo to list the CPU and system architecture
    # cat /proc/cpuinfo
  5. You can use the combination of the grep and wc commands as follows to print the output
    # grep processor /proc/cpuinfo | wc -l
    # echo "Total logical core(s): $(grep processor /proc/cpuinfo | wc -l)"
    Total logical core(s): 4
    # echo "Core per cpu: $(grep '^core id' /proc/cpuinfo | sort -u | wc -l)"
    Core per cpu: 4

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.