In this tutorial, we’ll delve a bit into our computer architecture. We’ll present a few ways on how to discover whether we’re using a 32-bit or a 64-bit Linux kernel, as well as discovering which of them are supported by our CPU.
2. Computer Architecture
In our computer architecture, we can differentiate three main components:
- Instruction set
- Memory addressing
- OS support
These are affected by whether we’re working with a 32-bit or a 64-bit architecture.
When we say the CPU implements a 64-bit instruction set, we mean our processor can work with values up to 64 bits directly. This usually includes registers, basic arithmetic, and floating-point instructions.
When we discuss memory addressing, this means we can use addresses up to a size of 64 bits to lookup data in the RAM. It’s the reason why 32-bit machines can’t handle more than 4 GB of RAM. In practice, even now, 64-bit processors only support up to 48-bit addresses (allowing for 256 TB of RAM).
Even if the CPU supports 64-bit instructions and memory addressing, we still need the OS to support these features.
3. Processor Support
Our first step will be to determine the capabilities of our CPU core.
To accomplish this, we’ll take a look at the contents of the /proc/cpuinfo file. This file provides all the info detected by the Linux kernel about our CPU. More information about this file can be found on the proc man page.
Most tools, including lscpu, use the data provided by this file to show a pretty representation of what we have on our system.
The processor presents the information under the flags entry via the lm (long mode) flag. For a full list of the various flags available, we can check the cpu features header file from the Linux kernel source.
Using grep, we find the first match for flags in /proc/cpuinfo (multiple matches will exist for every CPU core). We’ll pipe the result to a second grep so we can find the lm flag:
$ grep -m 1 flags /proc/cpuinfo | grep -o " lm " lm
This shows us a 64-bit processor is present. If a 32-bit processor is present, nothing will be printed.
4. Kernel Version
The most common way to query the current running kernel is via the uname command. This command returns a value of either x86_64 for a 64-bit kernel or i686 in case of a 32-bit kernel:
$ uname -m x86_64
Another common way to check whether the kernel has 64-bit support is via the getconf command:
$ getconf LONG_BIT 64
In this tutorial, we’ve seen multiple ways to get information about our CPU and the running kernel.