Modifying parent shell's attributes?

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

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

-austin

···

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?

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca

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

···

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

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

···

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.

Yep...thanks very much austin!

···

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

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

···

On Jan 1, 2008, at 9:59 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.

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

···

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

···

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.