Reputation: 369
Is there is a way to know dynamically Linux architecture, whether it x86-64
or x86
?
Upvotes: 0
Views: 505
Reputation: 1
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 (e.g. 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.
Upvotes: 4
Reputation: 9685
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.
Upvotes: 1