Modifying parent shell's attributes?

J

John Wells

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
 
A

Austin Ziegler

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
 
M

Marc Heiler

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
:)
 
J

John Wells

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
 
G

Gary Wright

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
 
J

John Wells

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

Gary Wright

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top