Prev: [ANN] os gem: initial release: easier platform management
Next: Building mysql extension/gem with MinGW (was Re: Gem build issuesUbuntu 9.10 64 bit)
From: Iñaki Baz Castillo on 14 Jan 2010 18:12 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ñaki Baz Castillo <ibc(a)aliax.net>
From: Rob Biedenharn on 14 Jan 2010 19:35 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. > > -- > Iñaki Baz Castillo <ibc(a)aliax.net> > You can use Fixnum#size to get number of bytes for a Fixnum and multiply by 8 bits/byte: irb(main):001:0> 1.size * 8 => 64 irb(main):002:0> RUBY_PLATFORM => "x86_64-linux" irb> 1.size * 8 => 32 irb> RUBY_PLATFORM => "universal-darwin9.0" I think it's reliable. (Although I guess there could be a 32-bit ruby running on a 64-bit platform.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob(a)AgileConsultingLLC.com
From: Seebs on 14 Jan 2010 22:16 On 2010-01-14, I�aki Baz Castillo <ibc(a)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. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Iñaki Baz Castillo on 15 Jan 2010 04:31 El Viernes, 15 de Enero de 2010, Seebs escribió: > On 2010-01-14, Iñaki Baz Castillo <ibc(a)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. The application I'm developing uses Posix Queue Messages thanks to posix_mq gem: http://bogomips.org/ruby_posix_mq/README.html 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: 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). -- Iñaki Baz Castillo <ibc(a)aliax.net>
From: Iñaki Baz Castillo on 15 Jan 2010 04:32
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: > > irb(main):001:0> 1.size * 8 > => 64 > irb(main):002:0> RUBY_PLATFORM > => "x86_64-linux" > > irb> 1.size * 8 > => 32 > irb> RUBY_PLATFORM > => "universal-darwin9.0" It's really good! Thanks a lot. -- Iñaki Baz Castillo <ibc(a)aliax.net> |