In Linux, the CPU information is stored in /proc/cpuinfo file. You can use programs like awk and grep to extract the number of CPU cores in Linux.
Example:
Check if hyper-threading is enabled in your system:
1 2 3 |
## Check if hyper-threading is enabled printf 'Hyperthreading '; \ sed -e s/1/enabled/ -e s/0/disabled/ /sys/devices/system/cpu/smt/active |
Get the number of CPU cores in Linux – without hyper-threading:
1 2 |
## Number of cpu core ((without hyper-threading)) grep -c ^processor /proc/cpuinfo |
Get the number of CPU cores in Linux – with hyper-threading:
1 2 |
## Number of cpu core (with hyper-threading) grep ^cpu\\scores /proc/cpuinfo | uniq | awk '{print $4}' |