Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

Linux CPU information

  • 20-09-2013 10:55AM
    #1
    Registered Users, Registered Users 2 Posts: 811
    ✭✭✭


    Hi i am trying to write a script to get the number of cores on a linux box
    on Redhat enterprise 6 no problem just issue the command nproc

    and it gives me the number of cores from cpu

    but we also have older version of Redhat this command does not exist

    I have tried this

    top -b -n 1 | grep CPU | wc -l

    cat /proc/cpuinfo | grep "processor" | wc -l


    but none of these count for hyper threading cores

    I need core count only


Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Registered Users, Registered Users 2 Posts: 1,110 Skrynesaver
    ✭✭✭


    cat /proc/cpuinfo | grep 'core id'


  • Registered Users, Registered Users 2 Posts: 811 Rambo
    ✭✭✭


    cat /proc/cpuinfo | grep 'core id'


    try that on a Red Hat Enterprise Linux AS release 3

    no output


  • Registered Users, Registered Users 2 Posts: 1,110 Skrynesaver
    ✭✭✭


    Don't have an RHEL3 box around I'm afraid...


  • Closed Accounts Posts: 18,966 syklops
    ✭✭✭✭




  • Moderators, Technology & Internet Moderators Posts: 1,336 croo
    Mod ✭✭✭✭


    My i7 has 4 cores but 8 CPU .. what do you want to count?
    If it were CPU then there will be an entry for each in the /proc/cpuinfo mentioned already so just count the number of "processor"s there are...
    cat /proc/cpuinfo | grep "processor" | wc -l
    
    should do it.
    If you wanted physical cores then there would be a little more work.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 811 Rambo
    ✭✭✭


    croo wrote: »
    My i7 has 4 cores but 8 CPU .. what do you want to count?
    If it were CPU then there will be an entry for each in the /proc/cpuinfo mentioned already so just count the number of "processor"s there are...
    cat /proc/cpuinfo | grep "processor" | wc -l
    
    should do it.
    If you wanted physical cores then there would be a little more work.

    yes physical cores I need


  • Registered Users, Registered Users 2 Posts: 2,771 niallb
    ✭✭✭


    OP does want physical cores though.
    Might save yourself time by just getting the cpu model name and looking it up on the manufacturer's website.
    You can return the correct number of cores from your script using a lookup table.
    Check for kernel 2.4.21 and return kludge()
    It's clumsy, dirty and might just fix your problem faster than solving it.


  • Banned (with Prison Access) Posts: 890 CrinkElite
    ✭✭✭


    Have you tried "lscpu"? I'm not on a linux box at the moment but it may have what you're looking for.


  • Registered Users, Registered Users 2 Posts: 811 Rambo
    ✭✭✭


    CrinkElite wrote: »
    Have you tried "lscpu"? I'm not on a linux box at the moment but it may have what you're looking for.

    yes on Redhat 6 Enterprise

    here the output

    [root@localhost ~]# lscpu
    Architecture: x86_64
    CPU op-mode(s): 64-bit
    CPU(s): 2
    Thread(s) per core: 1
    Core(s) per socket: 1
    CPU socket(s): 2
    NUMA node(s): 1
    Vendor ID: GenuineIntel
    CPU family: 6
    Model: 29
    Stepping: 1
    CPU MHz: 2400.085
    L1d cache: 32K
    L1i cache: 32K
    L2 cache: 3072K
    L3 cache: 12288K
    NUMA node0 CPU(s): 0,1

    but on older linux dist this command does not exists


  • Moderators, Technology & Internet Moderators Posts: 1,336 croo
    Mod ✭✭✭✭


    Rambo wrote: »
    yes physical cores I need
    ok. so what is in the /proc/cpuinfo file?
    I'm running ubuntu right now so it's probably a little different but to get the number of cores I would just count the number of different core id. From the link skylops provided I think the "core id" is called "physical id" so ...
    cat /proc/cpuinfo | grep "physical id" | uniq -c | wc -l
    
    should provide the number of cores.

    PS since it's an odl RHEL perhaps just show us what IS actually in the cpuinfo file?


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,771 niallb
    ✭✭✭


    It's a 2.4 kernel, so it's quite different.
    I only have RHEL3 still running on a virtual machine for compatibility with an old development environment when necessary, but here's the output from that:

    processor : 0
    vendor_id : GenuineIntel
    cpu family : 6
    model : 2
    model name : QEMU Virtual CPU version 0.9.1
    physical id : 255
    siblings : 1
    runqueue : 0
    stepping : 3
    cpu MHz : 1994.971
    cache size : 2048 KB
    fpu : yes
    fpu_exception : yes
    cpuid level : 2
    wp : yes
    flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm sse3
    bogomips : 3971.48
    clflush size : 64
    address sizes : 40 bits physical, 48 bits virtual
    power management:


Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement