#!/bin/ksh93

# exec > test4.out 2>&1

print "Test 4:  Alleges ksh93 is bypassing data ulimits by using mmap"

print "Setting 10MB Data ulimit"
set -x
ulimit -H -d 10240  # 10MB
ulimit -S -d 10240  # 10MB
set +x
[[ -x /usr/local/bin/proclimit ]] \
 && print "Query limits" && /usr/local/bin/proclimit -A $$

print
print "Memory layout beforehand"
set -x
/bin/pmap $$
set +x

unset PATH FPATH CDPATH

typeset -A stuff

print
print "Building memory usage:  1M iterations (leaks- see test3)"
typeset -lui i=0
for (( i=0; i<1000000; i++ ))
do
	unset stuff[xyz]
	typeset -A stuff[xyz]
	stuff[xyz][elem0]="data0"
	stuff[xyz][elem1]="data1"
	stuff[xyz][elem2]="data2"
	stuff[xyz][elem3]="data3"
	stuff[xyz][elem4]="data4"
	stuff[xyz][elem5]="data5"
	stuff[xyz][elem6]="data6"
	stuff[xyz][elem7]="data7"
	stuff[xyz][elem8]="data8"
	stuff[xyz][elem9]="data9"
	stuff[xyz][elem9]="data9"
done

print
print "Memory layout afterwards"
ulimit -H -d unlimited
ulimit -S -d unlimited
set -x
/bin/pmap $$
set +x
print  # Deliberate.  Make sure shell remains as parent.
