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


B

bfische

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
 
Ad

Advertisements

C

Carl

bfische said:
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.
 
T

Thomas Fritsch

bfische said:
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)
 
?

.

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.
 
B

bfische

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.
 
Ad

Advertisements

Joined
Sep 18, 2008
Messages
1
Reaction score
0
differntiate between 32bit and 64bit in linux

bfische said:
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


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top