How to detect CPU architecture/bitmode (32-bit vs. 64-bit) for Linux

Discussion in 'Java' started by bfische, Nov 15, 2005.

  1. bfische

    bfische Guest

    Hi List members,

    I have been trying to develop some code to figure out if a system is 32
    or 64-bits.
    I first thought about checking for the value of the Java System
    Property "os.arch" but that doesn't help as it doesn't specify the
    "bitness" of the processor.

    I need to differentiate between a Linux on x86-32 bit or x86-64
    (processor can be Intel or AMD) but I can't figure ou how.

    uname -p seems to work (gives i686) but I am not sure this will always
    return this (I don't have an AMD but I assume it will return a
    different value).

    Is there an OS command that print the hardware bit mode? (something
    like getconf HARDWARE_BITMODE on AIX).

    Thanks
    bfische, Nov 15, 2005
    #1
    1. Advertising

  2. bfische

    Carl Guest

    Re: How to detect CPU architecture/bitmode (32-bit vs. 64-bit) forLinux

    bfische wrote:
    > Hi List members,
    >
    > I have been trying to develop some code to figure out if a system is 32
    > or 64-bits.
    > I first thought about checking for the value of the Java System
    > Property "os.arch" but that doesn't help as it doesn't specify the
    > "bitness" of the processor.
    >
    > I need to differentiate between a Linux on x86-32 bit or x86-64
    > (processor can be Intel or AMD) but I can't figure ou how.
    >
    > uname -p seems to work (gives i686) but I am not sure this will always
    > return this (I don't have an AMD but I assume it will return a
    > different value).
    >
    > Is there an OS command that print the hardware bit mode? (something
    > like getconf HARDWARE_BITMODE on AIX).
    >
    > Thanks
    >

    bfische,

    The i686 you noticed in the output of uname does not necessarily
    indicate that the processor is or is not 64bit. Furthermore, the '-p'
    switch is a non-standard option for the uname command.
    http://www.opengroup.org/onlinepubs/007908799/xcu/uname.html

    You may want to look into parsing the contents of the /proc/cpuinfo
    file, though this is far from a portable solution and may be implemented
    differently in different platforms/distros.

    Just out of curiosity, why would you want to know the processor type in
    java?

    Carl.
    Carl, Nov 15, 2005
    #2
    1. Advertising

  3. "bfische" <> wrote:
    > I have been trying to develop some code to figure out if a system is 32
    > or 64-bits.
    > I first thought about checking for the value of the Java System
    > Property "os.arch" but that doesn't help as it doesn't specify the
    > "bitness" of the processor.

    On my platform (Java 1.5.0, WinXP (32bit)) there is a java system property
    sun.arch.data.model=32
    I suspect this gives the "bitness" of the CPU.
    (But be warned: You will enter the area of undocumented Sun-features)

    --
    "TFritsch$t-online:de".replace(':','.').replace('$','@')
    Thomas Fritsch, Nov 15, 2005
    #3
  4. bfische

    Roedy Green Guest

    On 14 Nov 2005 17:02:47 -0800, "bfische" <>
    wrote, quoted or indirectly quoted someone who said :

    >Is there an OS command that print the hardware bit mode? (something
    >like getconf HARDWARE_BITMODE on AIX).

    try running wassup on a 64 bit machine to dump all the system
    properties or write a little program to do that. See what turns up.
    http://mindprod.com/applets/wassup.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 15, 2005
    #4
  5. bfische

    . Guest

    Re: How to detect CPU architecture/bitmode (32-bit vs. 64-bit) forLinux

    On Tue, 15 Nov 2005, Thomas Fritsch wrote:

    > "bfische" <> wrote:
    > > I have been trying to develop some code to figure out if a system is 32
    > > or 64-bits.
    > > I first thought about checking for the value of the Java System
    > > Property "os.arch" but that doesn't help as it doesn't specify the
    > > "bitness" of the processor.

    > On my platform (Java 1.5.0, WinXP (32bit)) there is a java system property
    > sun.arch.data.model=32
    > I suspect this gives the "bitness" of the CPU.
    > (But be warned: You will enter the area of undocumented Sun-features)


    This will not give you the size of the CPU. This will give you the size of
    the JVM. Just to confirm this, I just tried on an HP-UX running on an
    Itanium2 (64 bit CPU) using a 32-bit JVM and sun.arch.data.model=32.

    --
    Send e-mail to: darrell dot grainger at utoronto dot ca
    ., Nov 15, 2005
    #5
  6. bfische

    bfische Guest

    Hi Carl,

    the reason why I am trying to detect the bitmode of the kernel is
    because I am writing an installer. Based on the OS Kernel bitmode,
    different set of libraries need to be laid down on the system.

    it seems like the uname -m actually gives x86_64 when it is an x86
    processor 64 bits (even for AMD processor). That's what I am using. I
    hope it will work on all Linux platforms.

    Carl wrote:
    > bfische wrote:
    > > Hi List members,
    > >
    > > I have been trying to develop some code to figure out if a system is 32
    > > or 64-bits.
    > > I first thought about checking for the value of the Java System
    > > Property "os.arch" but that doesn't help as it doesn't specify the
    > > "bitness" of the processor.
    > >
    > > I need to differentiate between a Linux on x86-32 bit or x86-64
    > > (processor can be Intel or AMD) but I can't figure ou how.
    > >
    > > uname -p seems to work (gives i686) but I am not sure this will always
    > > return this (I don't have an AMD but I assume it will return a
    > > different value).
    > >
    > > Is there an OS command that print the hardware bit mode? (something
    > > like getconf HARDWARE_BITMODE on AIX).
    > >
    > > Thanks
    > >

    > bfische,
    >
    > The i686 you noticed in the output of uname does not necessarily
    > indicate that the processor is or is not 64bit. Furthermore, the '-p'
    > switch is a non-standard option for the uname command.
    > http://www.opengroup.org/onlinepubs/007908799/xcu/uname.html
    >
    > You may want to look into parsing the contents of the /proc/cpuinfo
    > file, though this is far from a portable solution and may be implemented
    > differently in different platforms/distros.
    >
    > Just out of curiosity, why would you want to know the processor type in
    > java?
    >
    > Carl.
    bfische, Nov 24, 2005
    #6
  7. bfische

    jimmy

    Joined:
    Sep 18, 2008
    Messages:
    1
    differntiate between 32bit and 64bit in linux


    Its very simple bro...

    type (in liniux cmd prompt) : cat /proc/cpuinfo
    u will see some parameters with there discription

    under "flags" parameter u will see various values.
    Among them . u will find one of them with name "tm(transparent mode)" or
    "rm(real mode)" or "lm(long mode)"
    1. rm tells ,it is a 16 bit processor
    2. tm tells, it is a 32 bit processor
    3. lm tells, it is a 64 bit processor
    jimmy, Sep 18, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rashmi
    Replies:
    2
    Views:
    457
    Grumble
    Jul 5, 2005
  2. how to detect CPU architecture..

    , Sep 1, 2006, in forum: C Programming
    Replies:
    13
    Views:
    742
    SM Ryan
    Sep 1, 2006
  3. how to detect CPU architecture..

    , Sep 1, 2006, in forum: C Programming
    Replies:
    6
    Views:
    561
    Walter Roberson
    Sep 1, 2006
  4. Gowtham
    Replies:
    7
    Views:
    459
    Michael DOUBEZ
    Apr 15, 2008
  5. Pallav singh
    Replies:
    0
    Views:
    343
    Pallav singh
    Apr 1, 2009
Loading...

Share This Page