Wednesday, November 2, 2011

How to get detailed information about the machine's CPU in Linux

You can run the following command to see all information about the processors of the machine
    less /proc/cpuinfo

Note: This file shows logical cpu's seen by the OS on the machine, i.e. the CPU shown can be
- physical CPU
- hyperthreading 
- shared (e.g. dual or quad) core


Following command will return number of physical CPU's
    cat /proc/cpuinfo | egrep '(physical id).*:'  | sort -u | wc -l

Following command will return number of shared cores
    cat /proc/cpuinfo | egrep '(cpu cores).*:' | awk -F ":" '{print $2}'   | sort | uniq

If following command returns 1 then hyper-threading is disabled on then machine, if  >1 then hyper threading is enabled on the machine
    echo $(( `cat /proc/cpuinfo | egrep '(siblings).*:' | awk -F ":" '{print $2}'   | sort | uniq` \
           / `cat /proc/cpuinfo | egrep '(cpu cores).*:' | awk -F ":" '{print $2}'   | sort | uniq` ))

To get total virtual processors available to the OS, multiply above 3 values.

No comments:

Post a Comment