File: abyss-stack-size

package info (click to toggle)
abyss 2.3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,284 kB
  • sloc: cpp: 78,182; ansic: 6,512; makefile: 2,252; perl: 672; sh: 509; haskell: 412; python: 4
file content (25 lines) | stat: -rwxr-xr-x 671 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh

if [ $# -lt 2 ]; then
	echo "Usage: $(basename $0) <STACK_SIZE> <COMMAND>" >&2
	echo "Run COMMAND in a shell with a maximum stack size of" >&2
	echo "at least STACK_SIZE in kilobytes." >&2
	exit 1
fi
min_stack=$1; shift

# Note: A max stack size of "unlimited" may not actually
# be unlimited. For example, on Linux, using "unlimited"
# results in a max stack size of 2 MB, which
# is less than the default max stack size of 8 MB.
# How confusing!

stack=$(ulimit -s)
if [ "$stack" = "unlimited" ] || [ "$stack" -lt "$min_stack" ]; then
	ulimit -s $min_stack
fi
stack=$(ulimit -s)

echo "Running with max stack size of $stack KB: $*" >&2
exec /bin/sh -c "$*"