Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What is a Linux command that I can run to programmatically return either 32 or 64 to indicate whether the processor is a 32 bit or 64 bit processor?

share|improve this question
1  
@Sathya: That's not exactly a duplicate, because the processor can be 64-bit even if the Linux isn't. –  Gilles Nov 8 '10 at 0:07
add comment

4 Answers

up vote 10 down vote accepted
  • You can see whether the CPU is 64-bit, 32-bit, or capable of both by checking the flags line in /proc/cpuinfo. You have to know the possible flags on your architecture family. For example, on i386/amd64 platforms, the lm flag identifies amd64-capable CPUs (CPUs that don't have that flag are i386-only).

    grep -q '^flags *:.*\blm\b' /proc/cpuinfo    # Assuming a PC
    
  • You can see whether the kernel is 32-bit or 64-bit by querying the architecture with uname -m. For example, i[3456]86 are 32-bit while x86_64 is 64-bit. Note that on several architectures, a 64-bit kernel can run 32-bit userland programs, so even if the uname -m shows a 64-bit kernel, there is no guarantee that 64-bit libraries will be available.

    [ "$(uname -m)" = "x86_64" ]    # Assuming a PC
    
  • You can see what is available in userland by querying the LSB support with the lsb_release command. More precisely, lsb-release -s prints a :-separated list of supported LSB features. Each feature has the form module-*version*-architecture. For example, availability of an ix86 C library is indicated by core-2.0-ia32, while core-2.0-amd64 is the analog for amd64. Not every distribution declares all the available LSB modules though, so more may be available than is detectable in this way.

  • You can find out the preferred word size for development (assuming a C compiler is available) by compiling a 5-line C program that prints sizeof(void*) or sizeof(size_t).

share|improve this answer
3  
On GNU systems (and others if they have it), you should be able to do getconf WORD_BIT or getconf LONG_BIT instead of having to compile your own C program (trivial, and portable, though it is). –  Dennis Williamson Nov 8 '10 at 3:54
    
@Dennis: Thanks for the correction. I hadn't thought of using getconf here. It sounds nice in principle, but it's hard to ensure that the results apply to the particular C compiler you'll be using, if there's more than one (typically gcc/icc or similar on Linux, gcc/native cc elsewhere). On a standard system getconf should apply to c89 or c99 in $(getconf PATH), but in practice I'd worry about someone installing an alternate cc which is ran by the vendor c89 wrapper. –  Gilles Nov 8 '10 at 22:22
add comment

Type:

uname -a

If you get x86_64 GNU/Linux you're running a 64 bit kernel. If you get something similar to i386/i486/i586/i686 you're most probably running a 32 bit kernel

share|improve this answer
    
That's not the question. –  harrymc Nov 10 '10 at 19:17
add comment

You can use uname -a and look for x86_64 to see if you are running 64-bit. Anything else (As far as I know) and you are running 32-bit or you are on non-PC hardware such as alpha, sparc, or ppc64.

share|improve this answer
2  
Anything else and you're running 32-bit, or non-PC hardware (such as alpha, sparc64, ppc64, ... –  Gilles Nov 8 '10 at 0:08
    
@Gilles: Thanks, I edited my answer accordingly. –  Wuffers Nov 8 '10 at 0:11
add comment
uname -m | sed 's/x86_//;s/i[3-6]86/32/'
share|improve this answer
    
The g and the repetition aren't necessary. uname -m | sed 's/x86_//;s/i[3-6]86/32/' –  Dennis Williamson Nov 9 '10 at 2:45
    
Thanks, I've updated accordingly. –  WilliamKF Nov 16 '10 at 2:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.