LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2009, 10:42 AM   #1
raakin
LQ Newbie
 
Registered: Mar 2009
Location: At work
Distribution: none, yet
Posts: 3

Rep: Reputation: 0
CPU core count


I am needing to find the cpu core count on Linux systems due to software licensing and I would like to know a way to determine the cpu core count.

I have been trying:
Code:
cat /proc/cpuinfo | grep 'cpu cores'
Issues is 'cpu cores' does not always listed in the output, in the event of a single cpu system (from what I've seen).
Also, the above command will show show any number of lines per the same 'cpu id'

My question:
Is there a better way to display the cpu core count?
Is there a way to always display the cpu core count?
 
Old 03-18-2009, 11:20 AM   #2
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
cat /proc/cpuinfo | grep -i 'processor' | wc -l

See if this helps
 
Old 03-18-2009, 11:21 AM   #3
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
grep -i processor /proc/cpuinfo | wc -l

even this should work ...
 
Old 03-18-2009, 12:22 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
How do you want to treat enabled hyperthreading?

If I understand correctly, Windows licensing does not consider hyperthreading as increasing the number of cores, while the rest of the OS does treat hyperthreading as if it doubled the number of cores.

Consider a system with two physical CPU's, each of which has two cores, each of which is hyperthreaded. You will see 8 cores in Windows task manager or in top on Linux. A simplistic count of output from /proc/cpuinfo will also see 8 cores. If you parse /proc/cpuinfo output more carefully, you can see there are only 4 cores.

So first decide what exactly you want to count, then decide how to count it.
 
Old 03-18-2009, 03:04 PM   #5
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
probably this should be one - I will verify it tomorrow

cat /sys/devices/system/cpu/cpu0/topology/core_siblings_list

cat /sys/devices/system/cpu/present

if possible please paste the results for above commands

Last edited by asimba; 03-18-2009 at 03:06 PM.
 
Old 03-18-2009, 03:09 PM   #6
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
sorry missed on this one ... dmesg | grep -i cpu
 
Old 03-18-2009, 11:41 PM   #7
raakin
LQ Newbie
 
Registered: Mar 2009
Location: At work
Distribution: none, yet
Posts: 3

Original Poster
Rep: Reputation: 0
I want to count the number of cores, regardless of hyperthreading... I was waiting until tomorrow when I could test this on a box at work.

Thanks for the replies/posts and I will post my findings.
 
Old 03-19-2009, 07:14 AM   #8
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
lshw -C processor - will clearly show the number of physical CPU's and Logical CPU's (cores)

lshw is not installed by default on a lot of distros, but most should have it readily available in their repositories.
 
Old 03-19-2009, 07:32 AM   #9
asimba
Member
 
Registered: Mar 2005
Location: 127.0.0.0
Distribution: Red Hat / Fedora
Posts: 355

Rep: Reputation: 42
It works well for debian ( I have not checked if there are any rpm's for it for red hat).

there is similar tool - lshal - But in my case some of the information was missing.
 
Old 03-19-2009, 08:07 AM   #10
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by raakin View Post
I want to count the number of cores, regardless of hyperthreading.
That's actually an unclear answer to the question. But I think you mean that on a system with N actual cores, that because of hyperthreading appears to have 2*N cores, you want the answer N.

Most simple ways to count cores would give you 2*N. So if that isn't the answer you want, you should include a hyperthreaded system in your testing.

Quote:
I was waiting until tomorrow when I could test this on a box at work.
For licensing, I would think you want something that works across a wide range of systems (don't depend on packages that might not be installed or on dmesg state that is only available if there has been little activity since boot, etc.) and is moderately resistant to tampering.

For all that, I don't know a reasonable choice other than writing your own program to read and parse /proc/cpuinfo and understand a few different forms of the info that could appear there.
 
Old 03-19-2009, 04:06 PM   #11
raakin
LQ Newbie
 
Registered: Mar 2009
Location: At work
Distribution: none, yet
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by johnsfine View Post
That's actually an unclear answer
Sorry for being unclear but you are correct. I need to know the physical cores of the cpu, not the logical cores.

I did test out lshw -C processor and that command is not installed. Also, I don't have access to install it.

I agree that parsing out /proc/cpu seems to be the way to go for wider system compatibility.

Thank you all for your comments and sharing your information with me.
 
Old 05-06-2014, 02:36 PM   #12
vnspavan
LQ Newbie
 
Registered: May 2014
Posts: 1

Rep: Reputation: Disabled
Smile number of real CPU cores on your Linux system even when hyper threading is enabled

cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l

I found this command in one of the blogs and it works well.

Below Commands can be used to check Logical CPU's and need to check with the result of above command to check to see if hyper threading is enabled or not.

$ grep -c processor /proc/cpuinfo # Give the number of Logical CPU's
$ nproc # Give the number of Logical CPU's , CentOS v6+
$ lscpu | grep "CPU(s):" # Give the number of Logical CPU's more detailed , CentOS v6+
 
Old 05-06-2014, 03:12 PM   #13
Germany_chris
Senior Member
 
Registered: Jun 2011
Location: NOVA
Distribution: Debian 12
Posts: 1,069

Rep: Reputation: 497Reputation: 497Reputation: 497Reputation: 497Reputation: 497
it's a 5 year old thread
 
Old 08-01-2014, 12:58 AM   #14
linuxUser_
LQ Newbie
 
Registered: Aug 2014
Posts: 7

Rep: Reputation: Disabled
Hi Hope everyone doing fine,

I need a one line command to count number of cores in all processers.
My lappy is 8 core mechine (4 duel core processers) and i can see that 2 cores in each and every prcessor.
But my requirement is to get total number of cores with one line command.
Is there anything as such?

Thanks & Regards,
linuxUser_
 
Old 08-01-2014, 01:31 AM   #15
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
Duplicate post - answered elsewhere
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Intel DG33FB motherboard - cannot run second core on cpu (core 2 duo) rmitev Linux - Enterprise 2 09-28-2007 04:54 AM
Howto reduce CPU count bret Linux - General 1 09-26-2007 06:12 PM
`top` Irregularities - cpu count, percentage, process lists ColinAnderson Linux - Software 4 05-09-2007 06:41 PM
I want to count CPU cycles used by arbitrary code JonBrant Programming 4 11-10-2006 04:43 PM
%CPU , Memory Usage, Thread count srinivasar Programming 0 09-20-2003 03:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration