有没有办法动态了解Linux体系结构,无论是x86-64
还是x86
?
The Posix standard uname function (implemented in the uname(2) syscall) is dynamically giving you the information about the CPU. You probably want the machine
field.
Caution about x86-64 kernels running a 32 bit program (eg a 32 bits Debian distribution chroot
-ed in a 64 bits Debian, or perhaps a 32 bits ELF binary running on a 64 bits system); I have no idea what they give in that situation; I would imagine some x86_64
in that case, since the kernel does not really know about the binaries and libc
of the system.
See also the Linux specific personality(2) syscall.
Google is your friend: http://sourceforge.net/p/predef/wiki/Architectures/
You want to test for the macros __amd64__
and __i386__
. Ideally, you don't test the macros at all and write correct, portable code.
您可以使用lscpu命令列出有关CPU的特征。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.