How to discover the machine type?

29,668

Solution 1

arch ; uname -a

arch is the standard way to get the name of the CPU instruction set. uname -a gets a bunch of stuff about the OS. uname withouth the a gets the OS name.

However programmatically speaking, the equivalent to arch is uname -m.

Solution 2

You can try the following Perl one-liner:

perl -MConfig -e 'print "$Config{myarchname}\n";'

I know on Mac OS X Leopard with Perl 5.10.0 it prints "i386-darwin". I don't know of a way in Perl to get the actual processor name - your best bet is probably C since it's a fairly limited set of possibilities. You can get at a C compiler's predefined macros from Perl:

perl -MConfig -e 'print join("\n", split(/ /, $Config{cppsymbols})), "\n";'

This will list C macros like __LITTLE_ENDIAN__ and __MACH__ for Mach-O format and __i386__ (on Leopard at least), as well as the useless ones like __GNUC__ and __STDC__. Of course, all of this help assumes you have Perl on all machines. If not, I'm sure other languages have similar facilities to help you.

Solution 3

Why /proc/cpuinfo doesn't work?

I don't know all of the OSs you mentioned, but I think it give quite detailed information under Linux. At least, with the model of CPU, other informations can be looked up from a data table.

The software can only see what the OS let it to see, so if the OS doesn't provide informations like /proc/cpuinfo, then you'll have no way to know it.

reply to the comments:

I am not saying look for /proc/cpuinfo for all the OS. It's a two steps method: first you find out which OS it is using uname, then look for the OS specific position for the cpu info.

Solution 4

I would suggest you look at the facter component of the Puppet system. From the URL http://reductivelabs.com/projects/facter/.

A cross-platform Ruby library for retrieving facts from operating systems. Supports multiple resolution mechanisms, any of which can be restricted to working only on certain operating systems or environments. Facter is especially useful for retrieving things like operating system names, IP addresses, MAC addresses, and SSH keys.

Solution 5

This is not a complete answer, but it may help you reach your goal.

arch does not work on HP-UX Itanium, and it does not have the /proc filesystem, as you mentioned.

This explains how to determine the endianness (byte order) the O/S is using simply with shell commands. It works on at least 4 major Unixes (Linux x86_64, Solaris Sparc, AIX/Power, HP-UX Itanium). If you know the byte ordering you can deduce a lot about which CPU you're dealing with, based on this source.

For instance, if Solaris won't tell you the correct architecture, but you see that it's big endian, you at least know you're not on x86_64, and probably Sparc.

Finally, for Sparc you can do this to determine whether the OS is running in 32 or 64 bit mode:

# isalist -v
sparcv9+vis2 sparcv9+vis sparcv9 sparcv8plus+vis2 sparcv8plus+vis sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 sparc

If it says 'sparcv9' it's 64 bit, sparcv8 is 32

Share:
29,668
Giovanni Funchal
Author by

Giovanni Funchal

C/C++, Perl, Java, XHTML/CSS, SystemC, LaTeX, Makefile, Bash, PHP, VHDL, Tcl

Updated on August 24, 2022

Comments

  • Giovanni Funchal
    Giovanni Funchal almost 2 years

    I would like to discover the machine architecture type of a big number of machines. I have the hostname of each machine. The machines have Debian 4 linux, SunOS 9, SunOS 10 or Apple Darwin. All are unix-like, but with minor differences.

    I would like to know: - architecture (x86, x86_64, ia64, sparc, powerpc...) - processor type (intel pentium, pentium pro, pentium II, sparc, powerpc, itanium, athlon, core 2 duo, cytrix, etc...) - number of processors

    Beware, I want the "type" of the machine. The stupid approach using 'uname' does not work on Sun and it also returns things like 'i686' when the machine is in fact 'x86_64' but the operating system is 32 bits. /proc/cpuinfo doesn't work neither, and things get even more complicated because some machines dont have a C compiler installed (I'm sure they all have sh, perhaps python or perl, dunno).

    Thanks in advance!! :)

  • Giovanni Funchal
    Giovanni Funchal over 15 years
    Very probably ruby isn't installed on the machines :(
  • stephen mulcahy
    stephen mulcahy over 15 years
    +1 Reading /proc/cpuinfo or running dmidecode is the only sure-fire way to determine what processor you are running on. As you noted, uname reports the type of kernel you are running on and gives different results depending on the type of kernel that has been installed. Not sure about osx or sun.
  • Mike Heinz
    Mike Heinz over 15 years
    the /proc filesystem is a Linux invention, it does not exist on other UNIXes.
  • matli
    matli over 15 years
    Well, it is not a Linux invention, and it exists on other unix flavours, but it normally contains information about processes (hence its name), not random system information. Therefore this is not an answer to the question.
  • Giovanni Funchal
    Giovanni Funchal over 15 years
    arch? Didn't knew about it. I'll try.
  • vpalmu
    vpalmu over 12 years
    That is correct, but uname -m doesn't work on some really old systems. Unfortunately, arch is missing from debian, so you basically have to try one and if you get error try the other.
  • Cheeso
    Cheeso about 10 years
    On Centos 6.3 x64, it prints x86_64-linux