8

If I am working on a Unix machine, how could I know the size of the machine whether it is 64-bit or 32-bit machine?

George Kagan
  • 5,913
  • 8
  • 46
  • 50
Vijay
  • 65,327
  • 90
  • 227
  • 319

6 Answers6

17

AIX you can do this:

getconf KERNEL_BITMODE

HP-UX you can do this:

getconf KERNEL_BITS

or just:

getconf -a | grep KERN

Sun Solaris you can do this:

isainfo -v

For Linux, yes, the uname -a should do the trick

BrianH
  • 7,932
  • 10
  • 50
  • 71
  • as i am working on hp...getconf -a is not working... but getconf KERNEL_BITS is working fine. – Vijay Apr 14 '10 at 04:33
  • android ? :D ... i manage to install LinuxOnAndroid (rooted device) and getconf -a | grep KERN returns nothing :( also uname -m, or arch returns armv71 – THESorcerer Feb 06 '15 at 08:56
  • These commands only show the installed kernel bit size mode. For possible CPU modes, look in `lscpu` or at [another question's answer](https://stackoverflow.com/a/246014). – Dominik Oct 22 '17 at 13:36
7

You can type

uname -m 

if i686 or i386 is appearing, you are working with 32 bit if X86_64 is appearing, you are working with 64 bit

Harald Nordgren
  • 11,693
  • 6
  • 41
  • 65
Poyraz
  • 359
  • 1
  • 5
  • 12
6

I have to deal with a lot of Unix platforms and generally the best way I have found is to look at the output of "uname -a". For example, if you see something like "i686 i686 i386 GNU/Linux" in the output you know it's a 32 bit machine. If "amd64" shows up it's a 64. Sometimes it's a matter of trying to run a 64 bit programme. Sometimes it's RTFM.

Tim Allman
  • 1,501
  • 11
  • 8
2

If you're just looking to check the architecture of a machine you're on,

  %> uname -a

from the command line usually contains an indication in the output.

Adam Holmberg
  • 7,245
  • 3
  • 30
  • 53
1

You can also try sizeof(int *). Should be 4 on 32 bit machines and 8 on 64 bit machines.

JayM
  • 4,798
  • 1
  • 21
  • 15
  • There's no reason why I can't target a 32-bit executable on a 64-bit computer. Where I work, we haven't bothered changing some apps to 64 bits (although some eat memory by the gigabyte, and need to be run on 64-bit machines). – David Thornley Apr 08 '10 at 19:03
0

Assuming you want to do this at compile time - take a look here for architecture macros you can test. You are probably looking for __x86_64__.

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171