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

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

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

···

El Viernes, 15 de Enero de 2010, Walton Hoops escribió:

On 1/15/2010 9:59 AM, Iñaki Baz Castillo wrote:
> El Viernes, 15 de Enero de 2010, Iñaki Baz Castillo escribió:
>> 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'] = "linux-gnu" so finally it
>> ends doing:
>>
>> if (1<<32).class == Fixnum
>> 64
>> else
>> 32
>> end
>>
>> Which is basically the same as doing
>>
>> if 1.size == 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'] => "linux-gnu"
> RbConfig::CONFIG['host_cpu'] => "i486"
>
> b) 64 bits host:
>
> RbConfig::CONFIG['host_os'] => "linux-gnu"
> RbConfig::CONFIG['host_cpu'] => "x86_64"

submit a bug! GitHub - rdp/os: The OS gem allows for some easy telling if you’re on windows or not. OS.windows? as well as some other helper utilities

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?

--
Iñaki Baz Castillo <ibc@aliax.net>

I was to submit a report but Roger has already improved it :slight_smile:

···

El Viernes, 15 de Enero de 2010, Walton Hoops escribió:

submit a bug! GitHub - rdp/os: The OS gem allows for some easy telling if you’re on windows or not. OS.windows? as well as some other helper utilities

--
Iñaki Baz Castillo <ibc@aliax.net>

Makes sense, but I don't know enough about low-level OS/hardware to be sure that there isn't a CPU flag exposed that would still allow for an app or the OS to determine the bittedness of the CPU. So I asked and was answered :slight_smile:

···

On 1/15/2010 1:07 PM, Phillip Gawlowski wrote:

On 15.01.2010 20:56, Walton Hoops wrote:

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. If the OS isn't 64 bits itself, it'll run on an x86_64 architecture, but the CPU is in 32 bit mode. The only thing you can really test, is the bit-ness of the OS, not the CPU.

After all, how should a 32 bit OS deal with a 64 bit memory address?

--
Phillip Gawlowski

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 ➔ 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 ➔ (pickjdk 3 ; jruby -v -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) 64-Bit Server VM 1.6.0_17) [x86_64-java]
"64"

~/projects/jruby ➔ (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

···

On Fri, Jan 15, 2010 at 2:28 PM, Roger Pack <rogerpack2005@gmail.com> wrote:

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]. That wouldn't work for jruby (which always
returns 8), but should work fine for MRI, and I think we handle jruby
ok.

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.

···

On Fri, Jan 15, 2010 at 4:31 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:

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

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

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

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 :stuck_out_tongue:

-r

···

--
Posted via http://www.ruby-forum.com/.

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

- Charlie

···

On Fri, Jan 15, 2010 at 9:52 PM, Roger Pack <rogerpack2005@gmail.com> wrote:

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 :stuck_out_tongue: