Re: Exit codes for ulimit

From: Kasper Dupont (kasperd_at_daimi.au.dk)
Date: 12/02/04

  • Next message: zentara: "Re: Mysterious behavior in RedHat Linux"
    Date: Thu, 02 Dec 2004 13:51:09 +0100
    
    

    Caspar von Wrede wrote:
    >
    > Hi there,
    >
    > I need to run a shell script with limited CPU time and memory usage. The
    > best way to do this is using ulimit, right?
    >
    > I need to know which condition (time or memory), if any, the running script
    > violated. What is the best way of doing this? Do I use the exit codes, and
    > if so, what are they?

    First of all you have limits per process, not limits for
    the entire process tree. So if the script starts a lot of
    executables, each of them may use the full specified
    quota. (For most usages that minor detail is not a problem).

    When a process reaches the virtual memory limit any more
    attempts to allocate memory will return -ENOMEM, what the
    process does in this case depends on the individual program.
    Some may deal with it gracefully and print an error message
    like:

    mmap: Cannot allocate memory

    Others may be a litle less gracefull and you might get stuff
    like:

    a.out: test.c:13: main: Assertion `buf=malloc(size)' failed.
    Aborted (core dumped)

    Some may be even less well behaved and you might get

    Segmentation fault (core dumped)

    The script have to look on the return code from the actual
    executable running out of memory. And with each command you
    call from the script, you have to take care if that call
    could run out of memory.

    I think running out of CPU time is a litle easier for the
    script to deal with. Because the program is not offered
    any way to deal with it gracefully, it is just killed. You
    cannot cleanup without using more CPU time. I just tried
    this sequence of commands:

    [kasperd@frodo:pts/8:/] ulimit -t 1
    [kasperd@frodo:pts/8:/] md5sum /dev/urandom
    Killed
    [kasperd@frodo:pts/8:/] echo $?
    137
    [kasperd@frodo:pts/8:/]

    You should see something similar with any other program
    running out of CPU time.

    -- 
    Kasper Dupont
    

  • Next message: zentara: "Re: Mysterious behavior in RedHat Linux"

    Relevant Pages

    • Re: Problem with ASP on Webserver
      ... No, I know the memory model, I have made my own Virtual memory dump program ... function in the script ... (Accept-Language:) ...
      (microsoft.public.windowsce.platbuilder)
    • Re: Problem with ASP on Webserver
      ... Entrek's TOOLBOX is a lot better for memory stuff. ... function in the script ... (Accept-Language:) ...
      (microsoft.public.windowsce.platbuilder)
    • Critique my code: using Lisp to parse lots of "ps -elf" files in AIX
      ... It's my first use of Lisp at work, ... and another ksh script to analyze the output. ... success using them to diagnose some of their own memory problems, ... an hour to process about an hour's worth of data (i.e. 60 data files). ...
      (comp.lang.lisp)
    • Re: Out of Memory!
      ... My script is running on WinXP, Dos shell, which is a server program. ... unless it will pops-up a "Out of Memory!" ... Could someone tell me this error message is coming from Perl? ... This sub will be called every time a user Send or Get a mesg. ...
      (perl.beginners)
    • Re: Incude statement - is there such a thing?
      ... I can't imagine any memory usage issues. ... And it that WSF references ... other script files (as the Docs often suggest to be ... > you had 50 statements that you wanted to execute 1000 times in a loop. ...
      (microsoft.public.scripting.vbscript)