Using ulimit to limit the amount of memory a script can use

Solution 1:

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

#!/bin/bash

ulimit -v 100000
for i in {1..10000000}
do
    x="x"$x
done

The Bash man page says:

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

Solution 2:

Try to limit virtual memory:

ulimit -v 1024