ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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 tried the command cpuspeed but seemingly it's just
it will help you to get the speed and control priority of a daemon, you can set the max speed for a program
I am surprised (emotion just come when I realize some thing , "passing through my sense", I have my conception that deny death of itself ,it do not deny if death happen in other)
how to liberate ourself from these emotion to go faster in change , to feel the wind, to relax, to have fun? Please don't give any other emotion, I should deny emotion by be calm rather than contradict or escape it
I want an easy way to get the number of CPUs from a machine. The problem I have is that the info "cpu cores" is not there for every machine... in fact, it seems to only be there for multi-core processors. From an older dual Xeon (Woodcrest, I think):
processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2400.210
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
bogomips : 4802.15
processor : 1
vendor_id : GenuineIntel
cpu family : 15
model : 2
model name : Intel(R) Xeon(TM) CPU 2.40GHz
stepping : 7
cpu MHz : 2400.210
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe cid xtpr
bogomips : 4798.01
If somebody has a clever little shell-scripting way to get the number of CPUs out of that, that would be great... or another command to do so. I mean, I know I can just look through it and find the last instance of "processor" and then add one to the number following the last instance of that... but perhaps there's an easier way... or I could just stop being lazy and learn how to do this right
Can /proc/cpuinfo show number of distinct processors? How does it separate from a dual core machine from a two processor machine?
What separates a dual core from two singles? Not the two cores. It's the on-chip resources that might be shared in the dual core. If you can't tell the difference from /proc/cpuinfo then the distinction is elsewhere, i.e. unrelated to the cores.
ta0kira
Yes, let's keep this alive
Good idea to have a script at hand to fetch hardware info
started a small script to fetch some info.. work in progress
We are almost there... Well, I have access to two machines:
(A) A dual processor Opteron, single core on each.
(B) An Intel core-duo with dual core on a single processor.
I checked the cpuinfo on each. Machine A does not have a 'physical id' entry at all. Machine B has two such entries, both of which are zero, but not unique values as stated by BrianK.
The script only counts the rows, but doesn't check for unique IDs, so it can work correctly on Machine B. But it returns zero CPU COUNT and CORE PER CPU on Machine A.
I am assuming (just speculating) that machines that don't have dual(or multi) cores don't report physical ID in the cpuinfo. If this is the case, the script could check for the existence of this entry, and if none, it can report back only the number of rows with 'processor', and 1 as core per CPU.
Thank you BrianK for the physical ID idea and Uxinn for the script!
I tried the perl library, I think it is a bit outdated, but I prefer not needing to install any extras on the machines to make this work - So I stick to bash.
Here is an updated version with some more detail - a bit dirty, but that can be cleaned later.
Code:
#!/bin/bash
CPU_COUNT=`grep physical\ id /proc/cpuinfo |sort -u|wc -l`
CORE_COUNT=`grep core\ id /proc/cpuinfo |sort -u|wc -l`
CPU_MODEL=
CPU_VENDOR=`grep vendor_id /proc/cpuinfo|awk '{print $3}'|sort -u`
CPU_FREQ=`cat /proc/cpuinfo | grep "cpu MHz" | sort -u|sed 's/[^0-9\.]//g'`
OS_BIT=`uname -m`
KERNEL_VERSION=`uname -rsv`
#These are the distros I can test, don't have others installed
OS=`egrep -i 'red\ hat|suse|centos|ubuntu|debian' /etc/issue`
MEMORY_KB=`grep MemTotal: /proc/meminfo|awk '{ print $2 }'`
MEMORY_MB=`echo $MEMORY_KB / 1024|bc`"M"
if [ $OS_BIT == 'x86_64' ]; then
OS_BIT="64bit"
else
OS_BIT="32bit"
fi
if [ $CPU_COUNT == 0 ]; then
CPU_COUNT=1
CORE_COUNT=1
fi
if [ $CPU_VENDOR == 'GenuineIntel' ]; then
CPU_VENDOR="Intel"
CPU_TYPE=`grep model\ name /proc/cpuinfo|sort -u|awk '{print $5" "$7 $8 $9}'`
elif [ $CPU_VENDOR == 'AuthenticAMD' ]; then
CPU_VENDOR="AMD"
CPU_TYPE=`grep model\ name /proc/cpuinfo|sort -u|awk '{print $4 " " $5 " " $7}'`
fi
echo "CPU COUNT: " $CPU_COUNT
echo "CORE PER CPU: " $CORE_COUNT
echo "CPU VENDOR: " $CPU_VENDOR
echo "CPU Type: " $CPU_TYPE
echo "Platform: " $OS_BIT
echo "Operating System: " $OS
echo "Kernel Version: " $KERNEL_VERSION
echo "Total Memory: " $MEMORY_MB
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.