Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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+
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.