How to know the OS architecture (32 or 64 bits)?

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

El Viernes, 15 de Enero de 2010, Walton Hoops escribi=C3=B3:
El Viernes, 15 de Enero de 2010, I=C3=B1aki Baz Castillo escribi=C3=B3:
Note that to know the bits it uses "rbconfig" gem, and them:

Well, "rbconfig" is not a gem but a Ruby built in library.
In my server RbConfig::CONFIG['host_os'] =3D "linux-gnu" so finally it
ends doing:

if (1<<32).class =3D=3D Fixnum
64
else
32
end

Which is basically the same as doing

if 1.size =3D=3D 8
64
else
32
end

Definitively I don't like "os" gem at all. It could use
RbConfig::CONFIG['host_cpu'] rather than the not reliable
RbConfig::CONFIG['host_os']:


a) 32 bits host:

RbConfig::CONFIG['host_os'] =3D> "linux-gnu"
RbConfig::CONFIG['host_cpu'] =3D> "i486"

b) 64 bits host:

RbConfig::CONFIG['host_os'] =3D> "linux-gnu"
RbConfig::CONFIG['host_cpu'] =3D> "x86_64"
=20
submit a bug! http://github.com/rdp/os
=20
My main concern with that though:
Would RbConfig::CONFIG['host_cpu'] return "x86_64" if I'm running 32-bit
Linux on a 64-bit CPU?

No, I've tested it in a 64 bits server running Linux 32 bits:

RbConfig::CONFIG['host_os'] =3D> "linux-gnu"
RbConfig::CONFIG['host_cpu'] =3D> "i486"
1.size =3D> 4

=20


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
C

Charles Oliver Nutter

At least within a 32-bit OS (in a VM) it appears to be i686-linux so I
think we're safe there.

Also, thanks for the hint on 1.size I didn't know that one--it's
integrated now [v 0.6.1]. =C2=A0That wouldn't work for jruby (which alway= s
returns 8), but should work fine for MRI, and I think we handle jruby
ok.

If you really want to know if you're running on a 32 or 64-bit JVM (at
least for Hotspot) you can use this property:

~/projects/jruby =E2=9E=94 jruby -v -e "p ENV_JAVA['sun.arch.data.model']"
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-01-15 6586) (Java
HotSpot(TM) Client VM 1.5.0_19) [i386-java]
"32"

~/projects/jruby =E2=9E=94 (pickjdk 3 ; jruby -v -e "p ENV_JAVA['sun.arch.d=
ata.model']")
New JDK: 1.6.0
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-01-15 6586) (Java
HotSpot(TM) 64-Bit Server VM 1.6.0_17) [x86_64-java]
"64"

~/projects/jruby =E2=9E=94 (pickjdk 3 ; jruby -v -J-d32 -e "p
ENV_JAVA['sun.arch.data.model']")
New JDK: 1.6.0
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2010-01-15 6586) (Java
HotSpot(TM) Client VM 1.6.0_17) [i386-java]
"32"

There's probably something similar (or identical) for JRockit and J9.

- Charlie
 
R

Rick DeNatale

No, I've tested it in a 64 bits server running Linux 32 bits:

=A0RbConfig::CONFIG['host_os'] =A0=3D> "linux-gnu"
=A0RbConfig::CONFIG['host_cpu'] =3D> "i486"
=A01.size =3D> 4

I think that the value of 1.size depends not on what platform Ruby is
running on but how it was configured when Ruby was compiled.

You can have a version of Ruby compiled for 32-bits which runs on a
64-bit platform.

--=20
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
 
R

Roger Pack

Charles Nutter wrote:
ENV_JAVA['sun.arch.data.model']

Thanks I've included that.

@Trans "why this isn't in core"
I'm really not sure :p

-r
 
C

Charles Oliver Nutter

Charles Nutter wrote:
ENV_JAVA['sun.arch.data.model']

Thanks I've included that.

@Trans "why this isn't in core"
I'm really not sure :p

Seems like it could easily be an rbconfig value...

- Charlie
 

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

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top