Could you explain what you're trying to do? Without knowing why you think
you need to know this, it's hard to give you good advice. I couldn't tell
you off the top of my head whether the machine I'm working on right now is
32-bit or 64-bit. I've been doing software development on it for two years
and I've never needed to know.
-s
···
On 2010-01-14, Iñaki Baz Castillo <ibc@aliax.net> wrote:
Hi, is there a reliable way under Ruby to know the OS architecture (32 or 64
bits)?
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net | Seebs.Net <-- lawsuits, religion, and funny pictures Fair game (Scientology) - Wikipedia <-- get educated!
When the app runs it tries to create a posix mqueue with maxmsg=5000 and
msgsize=1024. The user running the application could have not permissions to
create such posix mqueue due to system limits ("ulimit -q").
In that case the creation of the posix mqueue raises a Errno::ENOMEM and I
want to tell the user the exact amount of bytes required.
The algorimth to know such amount of required bytes is:
In 32 bits sizeof(struct msg_msg *) is 4 bytes while in 64 it's 8 bytes, so
the total ammount of bytes changes. This means that "ulimit -q" must be
different depending on the system architecture (32/64 bits).
···
El Viernes, 15 de Enero de 2010, Seebs escribió:
On 2010-01-14, Iñaki Baz Castillo <ibc@aliax.net> wrote:
> Hi, is there a reliable way under Ruby to know the OS architecture (32 or
> 64 bits)?
Probably not.
Could you explain what you're trying to do? Without knowing why you think
you need to know this, it's hard to give you good advice. I couldn't tell
you off the top of my head whether the machine I'm working on right now is
32-bit or 64-bit. I've been doing software development on it for two years
and I've never needed to know.
El Viernes, 15 de Enero de 2010, Rob Biedenharn escribió:
On Jan 14, 2010, at 6:12 PM, Iñaki Baz Castillo wrote:
> Hi, is there a reliable way under Ruby to know the OS architecture
> (32 or 64
> bits)?
>
> I've just found RUBY_PLATFORM constant which returns "x86_64-linux"
> under 64
> bits, however it doesn't send very reliable for me.
>
> I need a way working under Linux and BSD. Thanks for any suggestion.
You can use Fixnum#size to get number of bytes for a Fixnum and
multiply by 8 bits/byte:
Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit system though.
On my Windows 7 x64 (with 32-bit ruby):
irb(main):005:0> OS.bits
=> 32
irb(main):006:0> 1.size
=> 4
irb(main):007:0>
···
On 1/15/2010 9:36 AM, Walton Hoops wrote:
On 1/14/2010 4:12 PM, Iñaki Baz Castillo wrote:
Hi, is there a reliable way under Ruby to know the OS architecture (32 or 64
bits)?
I've just found RUBY_PLATFORM constant which returns "x86_64-linux" under 64
bits, however it doesn't send very reliable for me.
I need a way working under Linux and BSD. Thanks for any suggestion.
I can't vouch for how accurate it is, but an OS gem was recently announced on this list.
gem install os
Correct me if I'm wrong, but don't 32bit apps running in a 64bit architecture run in a special space which mimics 32 bits? If that's the case, then I'd think the behaviour was as expected.
Matt
···
On Sat, 16 Jan 2010, Walton Hoops wrote:
On 1/15/2010 9:36 AM, Walton Hoops wrote:
On 1/14/2010 4:12 PM, Iñaki Baz Castillo wrote:
Hi, is there a reliable way under Ruby to know the OS architecture (32 or 64
bits)?
I've just found RUBY_PLATFORM constant which returns "x86_64-linux" under 64
bits, however it doesn't send very reliable for me.
I need a way working under Linux and BSD. Thanks for any suggestion.
I can't vouch for how accurate it is, but an OS gem was recently announced on this list.
gem install os
Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit system though.
On my Windows 7 x64 (with 32-bit ruby):
irb(main):005:0> OS.bits
=> 32
irb(main):006:0> 1.size
=> 4
irb(main):007:0>
Interesting, I'll take a look to its implementation. However in my case I will
never run 32 bits Ruby over a 64 bits SO.
···
El Viernes, 15 de Enero de 2010, Walton Hoops escribió:
On 1/15/2010 9:36 AM, Walton Hoops wrote:
> On 1/14/2010 4:12 PM, Iñaki Baz Castillo wrote:
>> Hi, is there a reliable way under Ruby to know the OS architecture
>> (32 or 64
>> bits)?
>>
>> I've just found RUBY_PLATFORM constant which returns "x86_64-linux"
>> under 64
>> bits, however it doesn't send very reliable for me.
>>
>> I need a way working under Linux and BSD. Thanks for any suggestion.
>
> I can't vouch for how accurate it is, but an OS gem was recently
> announced on this list.
> gem install os
>
> irb(main):001:0> require 'os'
> => true
> irb(main):002:0> OS.bits
> => 64
> irb(main):004:0> OS.posix?
> => true
> irb(main):005:0>
Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit
system though.
On my Windows 7 x64 (with 32-bit ruby):
irb(main):005:0> OS.bits
=> 32
irb(main):006:0> 1.size
=> 4
irb(main):007:0>
Note that to know the bits it uses "rbconfig" gem, and them:
def self.bits @bits ||= begin
require 'rbconfig'
host_os = RbConfig::CONFIG['host_os']
if host_os =~ /32/
32
else
if host_os =~ /64/
64
else # cygwin...
if (1<<32).class == Fixnum
64
else
32
end
end
end
end
end
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
···
El Viernes, 15 de Enero de 2010, Walton Hoops escribió:
On 1/15/2010 9:36 AM, Walton Hoops wrote:
> On 1/14/2010 4:12 PM, Iñaki Baz Castillo wrote:
>> Hi, is there a reliable way under Ruby to know the OS architecture
>> (32 or 64
>> bits)?
>>
>> I've just found RUBY_PLATFORM constant which returns "x86_64-linux"
>> under 64
>> bits, however it doesn't send very reliable for me.
>>
>> I need a way working under Linux and BSD. Thanks for any suggestion.
>
> I can't vouch for how accurate it is, but an OS gem was recently
> announced on this list.
> gem install os
>
> irb(main):001:0> require 'os'
> => true
> irb(main):002:0> OS.bits
> => 64
> irb(main):004:0> OS.posix?
> => true
> irb(main):005:0>
Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit
system though.
On my Windows 7 x64 (with 32-bit ruby):
irb(main):005:0> OS.bits
=> 32
irb(main):006:0> 1.size
=> 4
irb(main):007:0>
When the app runs it tries to create a posix mqueue with maxmsg=5000 and
msgsize=1024. The user running the application could have not permissions to
create such posix mqueue due to system limits ("ulimit -q").
Ahh.
The algorimth to know such amount of required bytes is:
In 32 bits sizeof(struct msg_msg *) is 4 bytes while in 64 it's 8 bytes, so
the total ammount of bytes changes. This means that "ulimit -q" must be
different depending on the system architecture (32/64 bits).
Ahh, yes. Although to be picky, you're now into one of the areas where, if
you ever end up on stranger hardware, the answer may be ill-defined; it
appears you care specifically about pointer sizes. There are some systems
where "pointer size" is not the same as "integer size", and so on... So
you could get some surprises.
I suspect Ruby tries to get a 64-bit fixnum if it can, so you're probably
set.
-s
···
On 2010-01-15, Iñaki Baz Castillo <ibc@aliax.net> wrote:
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net | Seebs.Net <-- lawsuits, religion, and funny pictures Fair game (Scientology) - Wikipedia <-- get educated!
No matter how many bits the OS has, as long the compiled interpreter
is 32 bits, the returned values is going to be 32 bits.
Windows can run 32bits applications along with 64bits ones, but that
doesn't mean you can access 64bits address space or tools from 32bits
applications.
···
On Jan 15, 1:40 pm, Walton Hoops <wal...@vyper.hopto.org> wrote:
On 1/15/2010 9:36 AM, Walton Hoops wrote:
> On 1/14/2010 4:12 PM, Iñaki Baz Castillo wrote:
>> Hi, is there a reliable way under Ruby to know the OS architecture
>> (32 or 64
>> bits)?
>> I've just found RUBY_PLATFORM constant which returns "x86_64-linux"
>> under 64
>> bits, however it doesn't send very reliable for me.
>> I need a way working under Linux and BSD. Thanks for any suggestion.
> I can't vouch for how accurate it is, but an OS gem was recently
> announced on this list.
> gem install os
Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit
system though.
On my Windows 7 x64 (with 32-bit ruby):
irb(main):005:0> OS.bits
=> 32
irb(main):006:0> 1.size
=> 4
irb(main):007:0>
Yes, for now I use 1.size to determine if I'm under 32 or 64 bits but it's
just a hack. Most probably I will code a small C extension method with returns
the exact value of sizeof(struct msg_msg *). Then the calculated valued would
be exact for any kinf of strange architecture (I hope).
Regards.
···
El Viernes, 15 de Enero de 2010, Seebs escribió:
> The algorimth to know such amount of required bytes is:
>
> queue.attr.mq_maxmsg * sizeof(struct msg_msg *) +
> queue.attr.mq_maxmsg * queue.attr.mq_msgsize
>
> In 32 bits sizeof(struct msg_msg *) is 4 bytes while in 64 it's 8 bytes,
> so the total ammount of bytes changes. This means that "ulimit -q" must
> be different depending on the system architecture (32/64 bits).
Ahh, yes. Although to be picky, you're now into one of the areas where, if
you ever end up on stranger hardware, the answer may be ill-defined; it
appears you care specifically about pointer sizes. There are some systems
where "pointer size" is not the same as "integer size", and so on... So
you could get some surprises.
Hmm.. it does not appear to deal with 32-bit ruby running on a 64 bit
system though.
On my Windows 7 x64 (with 32-bit ruby):
irb(main):005:0> OS.bits
=> 32
irb(main):006:0> 1.size
=> 4
irb(main):007:0>
No matter how many bits the OS has, as long the compiled interpreter
is 32 bits, the returned values is going to be 32 bits.
Windows can run 32bits applications along with 64bits ones, but that
doesn't mean you can access 64bits address space or tools from 32bits
applications.
On 2010-01-15, Iñaki Baz Castillo <ibc@aliax.net> wrote:
Most probably I will code a small C extension method with returns
the exact value of sizeof(struct msg_msg *). Then the calculated valued would
be exact for any kinf of strange architecture (I hope).
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net | Seebs.Net <-- lawsuits, religion, and funny pictures Fair game (Scientology) - Wikipedia <-- get educated!
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?
···
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?
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?
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 also added a .mac? method--if anybody on a mac could try it out
[and/or tell me what the RUBY_PLATFORM is for OS X and OS X 64 bit] then
I could actually test it.
Re: OS.bits on a 32 within a 64...anybody know how you can tell that
you're on 64 bit running a 32 bit ruby, on windows [or linux]?