uname -m gives i686 and
uname -m gives i686 i386 output in Red Hat Enterprise Linux Server release 5.4 (Tikanga) machine. I need to install Oracle Database 10g Release 2 on that machine. So, how can I decide whether kernel architecture is 32bit or 64bit?
@behrooz is correct. Unfortunately
uname requires you to know architectures. Actually, I was looking for a list of architectures and I found this article that answers your question. In regards to
x86_64 GNU/Linux indicates that you've a 64bit Linux kernel running. If you use see i386/i486/i586/i686 it is a 32 bit kernel.
To determine if the hardware is capable of running a 64-bit kernel
grep flags /proc/cpuinfo
Look for the following in the output (all flags retrieved from this stackoverflow answer for the same question )
lmflag means Long mode cpu - 64 bit CPU
tmflag means Protected mode - 32-bit CPU
rmflag means Real Mode - 16 bit CPU
If you're looking for a simple one-liner, this is the most reliable solution that I've found that returns 64 or 32. It doesn't care if you're running ARM or not, and it should work on any system using bash or sh.
Beware, this will assume the system is either 32-bit or 64-bit. See my explanation below if you need to detect 8- 16- or some-other-bit architecture.
[ $((0xffffffff)) -eq -1 ] && echo 32 || echo 64
What's happing here?
The logic is very simple and it all boils down to how computers store signed integers. A 32-bit architecture only has 32 bits that it can use for storing signed integers while a 64-bit architecture has 64 bits! In other words the set of integers that can be stored is finite. Half of this set represents negative numbers and half represents positive numbers. The signed integer equalling -1 is represented as the largest number that can be stored in a given number of bits for that architecture. On a 32-bit system, -1 can be represented by the hex value 0xFFFFFFFF (which is 32 binary bits, all equalling 1). On a 64-bit system, 0xFFFFFFFF translates to 4,294,967,295, base 10 while 0xFFFFFFFFFFFFFFFF is the representation for -1). You can see how this would easily scale for systems that are 8- or 16-bit as well which would equal -1 at 0xFF and 0xFFFF, respectively.