如何发现机器类型?
我想发现大量机器的机器架构类型。 我有每台机器的主机名。 这些机器有 Debian 4 linux、SunOS 9、SunOS 10 或 Apple Darwin。 所有这些都类似于 UNIX,但有细微的差别。
我想知道: - 架构(x86、x86_64、ia64、sparc、powerpc...) - 处理器类型(英特尔奔腾、奔腾 Pro、奔腾 II、sparc、powerpc、itanium、athlon、core 2 duo、cytrix 等) - 处理器数量
注意,我想要机器的“类型”。 使用“uname”的愚蠢方法在 Sun 上不起作用,当机器实际上是“x86_64”但操作系统是 32 位时,它还会返回“i686”之类的内容。 /proc/cpuinfo 也不起作用,事情变得更加复杂,因为有些机器没有安装 C 编译器(我确信它们都有 sh,也许是 python 或 perl,不知道)。
提前致谢!! :)
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!! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
拱形; uname -a
arch 是获取 CPU 指令集名称的标准方法。 uname -a 获取大量有关操作系统的信息。 uname 不带 a 获取操作系统名称。
然而从编程角度来说,
arch
的等价物是uname -m
。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
isuname -m
.您可以尝试以下 Perl 一行:
我知道在带有 Perl 5.10.0 的 Mac OS X Leopard 上它会打印“i386-darwin”。 我不知道 Perl 中有什么方法可以获取实际的处理器名称 - 你最好的选择可能是 C,因为它的可能性相当有限。 您可以从 Perl 获取 C 编译器的预定义宏:
这将列出 C 宏,例如 Mach-O 格式的
__LITTLE_ENDIAN__
和__MACH__
以及__i386__
(至少在 Leopard 上),以及像__GNUC__
和__STDC__
这样无用的。 当然,所有这些帮助都假设您在所有机器上都安装了 Perl。 如果没有,我相信其他语言也有类似的工具可以帮助您。You can try the following Perl one-liner:
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:
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.我建议你看看 Puppet 系统的 Factor 组件。 来自 URL http://reducinglabs.com/projects/facter/。
I would suggest you look at the facter component of the Puppet system. From the URL http://reductivelabs.com/projects/facter/.
为什么 /proc/cpuinfo 不起作用?
我不知道你提到的所有操作系统,但我认为它提供了 Linux 下相当详细的信息。 至少,通过CPU的型号,可以从数据表中查到其他信息。
软件只能看到操作系统让它看到的内容,因此如果操作系统不提供 /proc/cpuinfo 等信息,那么您将无法知道它。
回复评论:
我并不是说为所有操作系统查找 /proc/cpuinfo 。 这是一个两步方法:首先找出它正在使用 uname 的操作系统,然后查找 cpu 信息的操作系统特定位置。
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.
这不是完整的答案,但它可能会帮助您实现目标。
正如您提到的,arch 不适用于 HP-UX Itanium,并且它没有 /proc 文件系统。
这个 解释了如何通过 shell 命令简单地确定操作系统使用的字节顺序(字节顺序)。 它至少适用于 4 个主要 Unix(Linux x86_64、Solaris Sparc、AIX/Power、HP-UX Itanium)。 如果您知道字节顺序,您可以根据 this< 推断出您正在处理的 CPU 的很多信息/a> 来源。
例如,如果 Solaris 不会告诉您正确的体系结构,但您看到它是大端字节序,那么您至少知道您不在 x86_64 上,并且可能不在 Sparc 上。
最后,对于 Sparc,您可以执行以下操作来确定操作系统是在 32 位模式还是 64 位模式下运行:
如果显示“sparcv9”,则为 64 位,sparcv8 为 32 位
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:
If it says 'sparcv9' it's 64 bit, sparcv8 is 32
使用
uname -a
会给你带来很多信息,所以你必须搜索你想要的信息。只需使用:
用于硬件平台
或
机器硬件名称
The use of
uname -a
will bring you to much information, so you have to search for the information you want to have.Just use:
for the hardware platform
or
for the machine hardware name