Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an ubuntu system and I have a script that runs regularly. I need to limit the maximum amount of memory that this script can use. AFAIK ulimit is the command to do this, however I can't get it to work.

For example I have the following script:

#! /bin/bash

ulimit -m 1024

seq 100 | while read LINE ; do

This should make $X grow in size, and this example is just the kind of thing I want to limit. However the ulimit call doesn't seem to work. I can run the script OK, and it doesn't die, and top shows me that the script gets lots of memory. What am I doing wrong? How can I force this script to never user more than a certain amount of memory?

share|improve this question
up vote 4 down vote accepted

I was able to get the script to error out with the -v option:


ulimit -v 100000
for i in {1..10000000}

The Bash man page says:

-m            The  maximum resident set size (many systems do not honor
              this limit)
share|improve this answer

Try to limit virtual memory:

ulimit -v 1024 
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.