Re: Exit codes for ulimit
From: Kasper Dupont (kasperd_at_daimi.au.dk)
Date: 12/02/04
- Previous message: Gary Kato: "Re: Mysterious behavior in RedHat Linux"
- In reply to: Caspar von Wrede: "Exit codes for ulimit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Gary Kato: "Re: Mysterious behavior in RedHat Linux"
- In reply to: Caspar von Wrede: "Exit codes for ulimit"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|