Debian Codegraph @

bin/abyss-stack-size

raw
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4 echo "Usage: $(basename $0) <STACK_SIZE> <COMMAND>" >&2
5 echo "Run COMMAND in a shell with a maximum stack size of" >&2
6 echo "at least STACK_SIZE in kilobytes." >&2
7 exit 1
8 fi
9 min_stack=$1; shift
10
11 # Note: A max stack size of "unlimited" may not actually
12 # be unlimited. For example, on Linux, using "unlimited"
13 # results in a max stack size of 2 MB, which
14 # is less than the default max stack size of 8 MB.
15 # How confusing!
16
17 stack=$(ulimit -s)
18 if [ "$stack" = "unlimited" ] || [ "$stack" -lt "$min_stack" ]; then
19 ulimit -s $min_stack
20 fi
21 stack=$(ulimit -s)
22
23 echo "Running with max stack size of $stack KB: $*" >&2
24 exec /bin/sh -c "$*"
25