How do I know if my linux kernel is running in 32bit or 64bit?

14,323

Solution 1

uname -a

will tell you the kernel - the end bit tells you the architecture.

Two examples:

My mac:

Darwin Mac.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386

My Dreamhost hosting:

Linux ecco 2.6.24.5-serf-xeon-c6.1-grsec #1 SMP Tue Oct 7 06:18:04 PDT 2008 x86_64 GNU/Linux

i386 = 32 bit

x86_64 = 64 bit

Solution 2

uname -m will give you the architecture you kernel is compiled for. If it prints i686 then your kernel is 32 bit, if x86_64 then it's 64 bit, assuming you have an Intel/AMD chip.

Solution 3

I think the most precise way is

getconf LONG_BIT

here it exactly shows 64

found on this tip

getconf is from package libc-bin (on ubuntu)

Solution 4

If you want an easy but detailed report about your system (CPU, Kernel and Core OS software) and not just the kernel then here's a small bash script that will give you the answers swiftly.

If you know enough about the peculiarities of 32bit/64bit CPUs and S/W it's simply handy. If you don't know much and think that your "system" is either 32bit or 64bit then it will help you discover that the truth can be more complex (parts of your system may be 64bit while others 32bit) without confusing you.

Again this script (and answer) is not for the literal question "How do I know if my Linux kernel is running in 32bit or 64bit?" but for those who also want to know the arch of their CPU, and core OS SW.

Example reports

These are examples for a rather unusual case:

Report from mini-script (for experienced users)

You have a 64 bit CPU
Your kernel reports that the architecture is 32 bit
Your /sbin/init process is 64 bit
Your C compiler is configured to produce 32 bit executables

Report from larger script (for less experienced users)

You have a 64 bit CPU
Your kernel reports that the architecture is 32 bit
    If you are not the admin he can make a 64bit kernel report 32bit (see man setarch)
    In this case he has (because we have 64bit programs)
Your /sbin/init process is 64 bit
    Most other core OS programs will probably be 64 bits also.
    You may use the following command to check a specific program.
      file -L /path/to/program
Your C compiler is configured to produce 32 bit executables
    (Note that a 64bit compiler may be setup to produce 32bit code)

The scripts

Mini-script (for experienced admins)

These 4 lines gives all the essential information.

grep -w 'lm' /proc/cpuinfo > /dev/null && echo "You have a 64 bit CPU" || echo "You have a 32 bit CPU"
echo "Your kernel reports that the architecture is $(uname -m|sed -e 's/x86_64/64 bit/' -e 's/i.86/32 bit/')"
echo "Your /sbin/init process is $(file /sbin/init|sed -e 's/^.* \(32\|64\) bit.*$/\1bit/')"
echo "Your C compiler is configured to produce $(getconf LONG_BIT) bit executables"

Larger script (for less experienced users)

This script prints a lot of explanation and is useful if you don't have experience on the subject and are faced with a peculiar case.

#!/bin/bash

# collect system info
grep -w 'lm' /proc/cpuinfo > /dev/null && CPU=64 || CPU=32
ARCH=$(uname -m|sed -e 's/x86_64/64/' -e 's/i.86/32/')
INIT=$(file -L /sbin/init|sed -e 's/^.* \(32\|64\)-bit.*$/\1/')
COMPILER=$(getconf LONG_BIT)

# if all values are the same we set UNIFORM="YES"
! echo "$CPU $ARCH $INIT $COMPILER" | grep -q "$CPU $CPU $CPU $CPU" && UNIFORM="NO" || UNIFORM="YES"

# report to the user
echo "You have a $CPU bit CPU"
echo "Your kernel reports that the architecture is $ARCH bit"
if [ "$UNIFORM" = "NO" ] && [ "$ARCH" = "32" ] ; then
       echo "    If you are not the admin he can make a 64bit kernel report 32bit (see man setarch)"
       if  [ "$INIT" = "64" ] ||  [ "$COMPILER" = "64" ] ; then
           echo "    In this case he has (because we have 64bit programs)"
       else
           echo "    We don't see such signs so you most likely run a 32bit kernel"
           echo "    (A 64bit CPU can run 32bit kernels)"
       fi
fi
echo "Your /sbin/init process is $INIT bit"
if [ "$CPU" = "64" ] ; then
     echo "    Most other core OS programs will probably be $INIT bits also."
     echo "    You may use the following command to check a specific program."
     echo "      file -L /path/to/program"
fi
if [ "$UNIFORM" = "NO" ] && [ "$INIT" = "32" ] ; then
     echo "    (Note that a 64bit kernel may start a 32bit init process)"
fi
echo "Your C compiler is configured to produce $COMPILER bit executables"
if [ "$UNIFORM" = "NO" ] && [ "$COMPILER" = "32" ] ; then
        echo "    (Note that a 64bit compiler may be setup to produce 32bit code)"
fi

If you want to know more read these two pages from where I got most of the information a) https://stackoverflow.com/questions/246007/how-to-determine-whether-a-given-linux-is-32-bit-or-64-bit b) https://unix.stackexchange.com/a/134394/73271

Share:
14,323
Daniel Cukier
Author by

Daniel Cukier

Daniel is a technology innovator, currently exploring web3 projects. Former CTO in Brazilian startups such as Pravaler - a fintech that offers accessible student loans - also founder and CTO at Playax - an audience development platform for music professionals based on BigData - he also worked for two years as CTO at Elo7 – the biggest crafts marketplace in Brazil. Experienced working in different programming languages such as Elixir, Ruby, JavaScript and Java, Daniel helped many startups as venture advisor at Monashees Capital and other accelerator programs in Brazil. He is also PhD in Computer Science at University of São Paulo – IME-USP. His PhD research is about Software Startups Ecosystems and Entrepreneurship. Daniel mastered in Computer Science in University of São Paulo in 2009, with the Thesis Patterns for Introducing New Ideas in the Software Industry. Daniel is a Cloud Computing GDE (Google Developer Expert). Daniel started developing software in Brazil when he was 10, on his TK-3000 Basic 2MB RAM computer. He worked as a consultant and software developer in many companies. In 2001, he worked for an Internet startup in Italy. In 2006 he joined Locaweb, the biggest web hosting company in Brazil and worked there for 5 years as developer and tech lead in infrastructure team. Daniel is an active member in the agile and software development communities, speaker in many conferences such as Elixir Brasil, QCON, Agile Brasil, TDC, DevCamp, Agile Trends and others. Studying other Arts beside software development, like Theatre, musical instruments and compositions, dance and writing, he acted in five musical plays and has a poetry book published. Daniel is a Vipassana meditation student and is very interested in topics related to human consciousness.

Updated on September 17, 2022

Comments

  • Daniel Cukier
    Daniel Cukier almost 2 years

    When I do a cat in /proc/cpuinfo it shows a line with clflushsize : 64

    Does this mean my kernel is running in 64 bits?

  • a_m0d
    a_m0d almost 15 years
    Could also be i386 on older 32-bit platforms (and I have even seen some packages compiled for i586 - not sure if that would ever be output by uname, though)
  • Drona
    Drona almost 15 years
    uname -i prints GenuineIntel, which isn't really what he's looking for.
  • Rich Bradshaw
    Rich Bradshaw almost 15 years
    and Unknown on a Mac.
  • a_m0d
    a_m0d almost 15 years
    prints i386 on my machine!
  • David Schwartz
    David Schwartz almost 9 years
    This answer is wrong. uname -m gives you the architecture the kernel chooses to expose to this particular process, not the kernel's native architecture. See this link.
  • David Schwartz
    David Schwartz almost 9 years
    This answer is wrong. The end bit tells you the architecture exposed to the process, not the kernel architecture. See this link.
  • ndemou
    ndemou over 8 years
    @David Schwartz: Your comment is too harsh for no good reason and the fact that you've posted no alternative is making it look even worse. Anyway note that by default uname -m does report the real architecture. If it's not, then most likely the admin really-really wants you to believe you're on that other architecture and your best bet is to accept that he knows what he's doing. If you are the admin and you're messing with setarch then you already know better anyway.
  • David Schwartz
    David Schwartz over 8 years
    I don't know what's harsh about the true factual statement that the answer is wrong. What do ou mean by "making it look even worse". Maybe there is no way. Maybe there is a good way. I don't happen to know, so I didn't answer this question. As for the end of your comments, I just don't agree. Scripts can, and do, use setarch and you might invoke such a script without having any idea that it causes uname -m to return something different. It's possible, maybe even likely, that these kinds of issues are why the OP is asking.
  • Ruslan
    Ruslan about 8 years
    @ndemou the admin may have set the system up in such a way that any application including init thinks it's 32-bit: the situation for this is 64-bit kernel with 32-bit userspace. Many compilation systems depend on uname -m to determine compiler flags, e.g. that of GDB, they must be supplied with fake personality. But some other userspace application can still want to know what type of kernel it has (e.g. for some low-level needs), regardless of personality.