Shell script to find max available user memory

Ken Turkowski ken at turtlevax.UUCP
Wed Dec 5 07:25:46 AEST 1984


This shell script should determine the amount of available physical memory.
Please test it out on your system, and mail me any problems and enhancements.

-----------------------------------------------------------------

# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# usermem

echo x - usermem
cat > "usermem" << '//E*O*F usermem//'
#! /bin/sh
# This shell script snoops around to find the maximum amount of user memory.
# These variables need to be set only if there is no /usr/adm/messages
KMEM=/dev/kmem		# User needs read access to KMEM
# For VAX, CLICKSIZE = 512 bytes
# For PDP-11, CLICKSIZE = 64 bytes
# For CADLINC 68000, CLICKSIZE = 4096 bytes
CLICKSIZE=512

size=0
if [ -r /usr/adm/messages ]	# probably the most transportable
then
    size=`grep avail /usr/adm/messages | sed -n '$s/.*[ 	]//p'`
fi

if [ 0$size -le 0 ]		# no size in /usr/adm/messages
then
    if [ -r $KMEM ]
    then
	if [ -r /vmunix ]
	then
	    UNIX=/vmunix
	    CLICKSIZE=512	# Probably VAX
	elif [ -r /unix ]
	then
	    UNIX=/unix
	fi
	size=`echo maxmem/D | adb $UNIX $KMEM | sed -n '$s/.*[ 	]//p'`
	if [ 0$size -le 0 ]
	then
	    size=`echo physmem/D | adb $UNIX $KMEM | sed -n '$s/.*[ 	]//p'`
	fi
	size=`expr 0$size '*' $CLICKSIZE`
    fi
fi

if [ 0$size -le 0 ]
then
    echo 0
else
    echo $size
fi
//E*O*F usermem//

echo Possible errors detected by \'sum\' [hopefully none]:
temp=/tmp/shar$$
trap "rm -f $temp; exit" 0 1 2 3 15
cat > $temp <<\!!!
33817     1
!!!
sum  usermem | sed 's=[^ ]*/==' | diff -b $temp -
exit 0

-- 
Ken Turkowski @ CADLINC, Menlo Park, CA
UUCP: {amd,decwrl,flairvax,nsc}!turtlevax!ken
ARPA: turtlevax!ken at DECWRL.ARPA



More information about the Comp.unix.wizards mailing list