Modifying parent shell's attributes?

Discussion in 'Ruby' started by John Wells, Dec 13, 2007.

  1. John Wells

    John Wells Guest

    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
     
    John Wells, Dec 13, 2007
    #1
    1. Advertisements

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

    -austin
     
    Austin Ziegler, Dec 13, 2007
    #2
    1. Advertisements

  3. John Wells

    Marc Heiler Guest

    Check out the Process class; specifically getrlimit and setrlimit. It

    These are the little diamond things in ruby - bits of useful knowledge
    :)
     
    Marc Heiler, Dec 13, 2007
    #3
  4. John Wells

    John Wells Guest

    Yep...thanks very much austin!
     
    John Wells, Dec 13, 2007
    #4
  5. John Wells

    John Wells Guest

    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
     
    John Wells, Jan 2, 2008
    #5
  6. John Wells

    Gary Wright Guest

    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:
    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
     
    Gary Wright, Jan 2, 2008
    #6
  7. John Wells

    John Wells Guest

    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]
     
    John Wells, Jan 2, 2008
    #7
  8. John Wells

    Gary Wright Guest

    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
     
    Gary Wright, Jan 2, 2008
    #8
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.