All processors that support the x64 instruction set (also known as x86_64 or amd64) also support the x86 instruction set (also known as i386 or i686, which are strictly speaking specific versions of x86). The same goes for ARM A64 (the new 64-bit instruction set appearing in ARMv8) and A32 (the name for the “classic” 32-bit instruction set), for SPARC64 and SPARC, and I believe for MIPS64 and MIPS. So on all these architecture families, if a processor can run 64-bit code, it can also run 32-bit code.
The Linux kernel supports running 32-bit userland code with a 64-bit kernel (on all the architecture families mentioned above, I think). The kernel must be homogeneous (all 64-bit or all 32-bit), and each process must be homogeneous, but you can have a mixture of 32-bit and 64-bit processes on a 64-bit kernel. The converse is not possible: with a 32-bit kernel, you cannot run 64-bit processes.
This is a design choice in Linux, motivated by the desire to run existing 32-bit binaries on 64-bit installations. Other Unix variants have made different choices: Solaris can run 64-bit programs on a 32-bit kernel as well as the other way round, while OpenBSD cannot run 32-bit programs on a 64-bit kernel.
You can get information about the CPU in /proc/cpuinfo
. If your x86 CPU has the lm
flag, it's a 64-bit CPU.
By default, uname -m
or arch
shows the architecture that the kernel was compiled for. Linux can set the “personality” of a process (with the personality
) system call. You can run a subprocess in a different personality with the setarch
command; setarch i686 someprogram
or linux32 someprogram
runs the specified program in an environment where uname -m
returns i686
while setarch amd64 someprogram
or linux64 someprogram
runs the specified program in an environment where uname -m
returns amd64
.
file /sbin/init
tells you what architecture the init
program is compiled for. Although it's possible to mix 32-bit and 64-bit executables in an installation, usually all the core OS programs are from the same architecture, because it's a lot easier to manage.
$HOSTYPE
is a bash variable and tells you what architecture the bash
program was compiled for.
getconf LONG_BIT
lets you know whether the default C compiler is set up to compile 32-bit or 64-bit programs. A more precise test is to compile a and run a program that prints sizeof(void*)
or sizeof(size_t)
— calling getconf
can only give information about what getconf
thinks is the default compiler.