[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Modifying parent shell's attributes?

John Wells

12/13/2007 1:32:00 PM

I asked this on the rails list, but received no traction. Since it's
more of a ruby question anyway, thought I'd give it a shot here.

I have a problem with one of my rake tasks. It loads a very large yaml
file into the db, but because of the default limitation on stack size
in the Linux shell, the task craps out. Executing "ulimit -s 16384"
fixes the issue, and the task completes just fine.

What I'd like to do within my task is this (in ruby-ish pseudo):

if on_linux?
set_stack_of_running_shell_via_ulimit 16384
end

Is there any way to do this? Can I modify the attributes of the shell
that is running me?

Thanks!
John

7 Answers

Austin Ziegler

12/13/2007 2:18:00 PM

0

On 12/13/07, John Wells <lists@sourceillustrated.com> wrote:
> I asked this on the rails list, but received no traction. Since it's
> more of a ruby question anyway, thought I'd give it a shot here.
>
> I have a problem with one of my rake tasks. It loads a very large yaml
> file into the db, but because of the default limitation on stack size
> in the Linux shell, the task craps out. Executing "ulimit -s 16384"
> fixes the issue, and the task completes just fine.
>
> What I'd like to do within my task is this (in ruby-ish pseudo):
>
> if on_linux?
> set_stack_of_running_shell_via_ulimit 16384
> end
>
> Is there any way to do this? Can I modify the attributes of the shell
> that is running me?

Check out the Process class; specifically getrlimit and setrlimit. It
won't change the shell, but it will change Ruby.

-austin
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca

Marc Heiler

12/13/2007 4:14:00 PM

0

> Check out the Process class; specifically getrlimit and setrlimit. It
> won't change the shell, but it will change Ruby.
>
> -austin


These are the little diamond things in ruby - bits of useful knowledge
:)
--
Posted via http://www.ruby-....

John Wells

12/13/2007 9:41:00 PM

0

On 12/13/07, Marc Heiler <shevegen@linuxmail.org> wrote:
> > Check out the Process class; specifically getrlimit and setrlimit. It
> > won't change the shell, but it will change Ruby.
> >
> > -austin
>
>
> These are the little diamond things in ruby - bits of useful knowledge
> :)

Yep...thanks very much austin!

John Wells

1/2/2008 3:00:00 AM

0

On 12/13/07, Austin Ziegler <halostatue@gmail.com> wrote:
> On 12/13/07, John Wells <lists@sourceillustrated.com> wrote:
> > I asked this on the rails list, but received no traction. Since it's
> > more of a ruby question anyway, thought I'd give it a shot here.
> >
> > I have a problem with one of my rake tasks. It loads a very large yaml
> > file into the db, but because of the default limitation on stack size
> > in the Linux shell, the task craps out. Executing "ulimit -s 16384"
> > fixes the issue, and the task completes just fine.
> >
> > What I'd like to do within my task is this (in ruby-ish pseudo):
> >
> > if on_linux?
> > set_stack_of_running_shell_via_ulimit 16384
> > end
> >
> > Is there any way to do this? Can I modify the attributes of the shell
> > that is running me?
>
> Check out the Process class; specifically getrlimit and setrlimit. It
> won't change the shell, but it will change Ruby.

Following up a bit late on this, but this doesn't solve my problem.
for some reason.

I have tried:

Process.setrlimit Process::RLIMIT_STACK, Process::RLIM_INFINITY,
Process::RLIM_INFINITY
Process.setrlimit Process::RLIMIT_STACK, 0, Process::RLIM_INFINITY

Is this the proper usage? It still craps out with same error, but
setting ulimit in the calling shell to 16000 works just fine.

Thanks!
John

Gary Wright

1/2/2008 3:20:00 AM

0


On Jan 1, 2008, at 9:59 PM, John Wells wrote:
>
> I have tried:
>
> Process.setrlimit Process::RLIMIT_STACK, Process::RLIM_INFINITY,
> Process::RLIM_INFINITY
> Process.setrlimit Process::RLIMIT_STACK, 0, Process::RLIM_INFINITY
>

It looks like you are trying to increase the max stack size
to RLIM_INFINITY, which can only be done if you have super-user
access. What you want to do is to just raise the soft-limit. Try the
following in IRB and see if it works on your system:

>> include Process
=> Object
>> s = getrlimit RLIMIT_STACK
=> [8388608, 67108864]
>> setrlimit RLIMIT_STACK, s.first*2, s.last
=> nil
>> getrlimit RLIMIT_STACK
=> [16777216, 67108864]
>>

In this example, I'm just changing the stack limit to twice its
default size, which is still less than the max limit of 67108864.

This example was done on a Mac OS 10.4 system.

Gary Wright

John Wells

1/2/2008 3:38:00 AM

0

On 1/1/08, Gary Wright <gwtmp01@mac.com> wrote:
>
> On Jan 1, 2008, at 9:59 PM, John Wells wrote:
> >
> > I have tried:
> >
> > Process.setrlimit Process::RLIMIT_STACK, Process::RLIM_INFINITY,
> > Process::RLIM_INFINITY
> > Process.setrlimit Process::RLIMIT_STACK, 0, Process::RLIM_INFINITY
> >
>
> It looks like you are trying to increase the max stack size
> to RLIM_INFINITY, which can only be done if you have super-user
> access. What you want to do is to just raise the soft-limit. Try the
> following in IRB and see if it works on your system:
>
> >> include Process
> => Object
> >> s = getrlimit RLIMIT_STACK
> => [8388608, 67108864]
> >> setrlimit RLIMIT_STACK, s.first*2, s.last
> => nil
> >> getrlimit RLIMIT_STACK
> => [16777216, 67108864]
> >>

I'm on Linux, and I've even done this:

Process.setrlimit Process::RLIMIT_STACK, 18446744073709551615,
18446744073709551615

And, based on what getrlimit says, it worked. However, same exception.

Even doing it as root, nothing else seems to work but ulimit -s 16000
from parent shell.

ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]

Gary Wright

1/2/2008 3:50:00 AM

0


On Jan 1, 2008, at 10:38 PM, John Wells wrote:
>
> I'm on Linux, and I've even done this:
>
> Process.setrlimit Process::RLIMIT_STACK, 18446744073709551615,
> 18446744073709551615
>
> And, based on what getrlimit says, it worked. However, same exception.
>
> Even doing it as root, nothing else seems to work but ulimit -s 16000
> from parent shell.

I'd avoid huge numbers like that--you may be causing other problems
because you are overcommitting memory. Just try using the same value
you have had success with via ulimit: 16384000 (in bytes).

How about calling Process.setrlimit in Ruby and then forking to
run your actually code?

Process.setrlimit Process::RLIMIT_STACK, new_limit, new_max

child = fork { do_work }
Process.wait(child)



Gary Wright