How to get number of main CPU/Core using Bash? (Solved)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

How to get number of main CPU/Core using Bash? (Solved)

#1 Post by LazY Puppy »

Hi.

I need to find out how many main CPU/Core are on the mother board.

How can I do this in bash?

Thanks.
Last edited by LazY Puppy on Sat 19 Dec 2015, 07:25, edited 1 time in total.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

unicorn316386

#2 Post by unicorn316386 »

I did this and got 1 :lol: (might try '..$' if more than 9)

Code: Select all

grep -r "cpu cores" /proc/cpuinfo | grep -o '.$'

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#3 Post by rufwoof »

Hmm! Puppy pc single core on desktop 1, rdp'd into another puppy with 4 cores on desktop 2, and rdp'd into a windows box with 4 cores on desktop 3, and rdp'd into a android on desktop 4 = TEN

But /proc/cpuinfo is only showing ONE ???

:) :) :)

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#4 Post by LazY Puppy »

Ok.

Terminal Output:

Code: Select all

root# CORES=`grep -r "cpu cores" /proc/cpuinfo | grep -o '.$'`; echo $CORES
2 2
root#
Prozessor is: Intel(R) Core(TM)2 Duo CPU E6750 @ 2.66GHz

File /proc/cpuinfo shows processor 0 and processor 1

Processor 0 cpu cores shows 2
Processor 1 cpu cores shows 2 also

So this means the mother board has 2 CPU and each CPU has 2 cores?

So there are 4 cores, no?
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

unicorn316386

#5 Post by unicorn316386 »

@LazY Puppy: Your E6750 has 2 cores in total, but looks like lscpu can break it down better :lol:

Actual Cores:

Code: Select all

lscpu | grep -i "Core(s)" | grep -o ".$"
Threads / Virtual Cores (should double only if there's hyper-threading):

Code: Select all

lscpu | grep -i "CPU(s):" | grep -o ".$"
The top result seems to match with the Intel definition of a core/CPU from what I can tell
http://ark.intel.com/products/30784/Intel-Core2-Duo-Processor-E6750-4M-Cache-2_66-GHz-1333-MHz-FSB
Cores is a hardware term that describes the number of independent central processing units in a single computing component (die or chip).
@rufwoof: I guess each puppy has it's own /proc/cpuinfo ? Never tried rdp so your guess is probably better than mine :D

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

Solved

#6 Post by LazY Puppy »

Thanks to everyone for the replies.

Marked as solved.
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#7 Post by amigo »

cpuinfo only reflects the *capacity* of the cpu, without telling you how many cores are actually being used. This:

Code: Select all

$ ls /sys/devices/system/cpu/
cpu0  cpufreq  kernel_max  offline  possible  present  release
cpu1  cpuidle  modalias    online   power     probe    uevent
$ cat /sys/devices/system/cpu/kernel_max 
255
$ cat /sys/devices/system/cpu/offline 
2-63
$ cat /sys/devices/system/cpu/possible 
0-63
$ cat /sys/devices/system/cpu/present 
0-1
$ cat /sys/devices/system/cpu/online 
0-1
The last two commands are the most telling.

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#8 Post by Karl Godt »

cpu frequency scaling is another way to check if the CPU is a Core or a Thread .

Code: Select all

# file /sys/devices/system/cpu/cpu[0-9]/cpufreq
/sys/devices/system/cpu/cpu0/cpufreq: directory
/sys/devices/system/cpu/cpu1/cpufreq: directory
/sys/devices/system/cpu/cpu2/cpufreq: symbolic link to `../cpu0/cpufreq'
/sys/devices/system/cpu/cpu3/cpufreq: symbolic link to `../cpu1/cpufreq'

The links are for threads, directories are for cores ( I think kernel 2.6.37.4-KRG-p4_1 ) .

Post Reply