first pass for new make
[unix-history] / usr / src / usr.bin / compress / usermem.sh
CommitLineData
64d06f2f
KM
1#!/bin/sh -
2#
58777538
KB
3# Copyright (c) 1985 The Regents of the University of California.
4# All rights reserved.
5#
6# This code is derived from software contributed to Berkeley by
7# James A. Woods, derived from original work by Spencer Thomas
8# and Joseph Orost.
9#
10# Redistribution and use in source and binary forms are permitted
11# provided that the above copyright notice and this paragraph are
12# duplicated in all such forms and that any documentation,
13# advertising materials, and other materials related to such
14# distribution and use acknowledge that the software was developed
15# by the University of California, Berkeley. The name of the
16# University may not be used to endorse or promote products derived
17# from this software without specific prior written permission.
18# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21#
b528bd5e 22# @(#)usermem.sh 5.6 (Berkeley) %G%
64d06f2f
KM
23#
24: This shell script snoops around to find the maximum amount of available
25: user memory. These variables need to be set only if there is no
26: /usr/adm/messages. KMEM, UNIX, and CLICKSIZE can be set on the command
27: line, if desired, e.g. UNIX=/unix
28KMEM=/dev/kmem # User needs read access to KMEM
29UNIX=
30# VAX CLICKSIZE=512, UNIX=/vmunix
31# PDP-11 CLICKSIZE=64, UNIX=/unix
32# CADLINC 68000 CLICKSIZE=4096, UNIX=/unix
33# Perkin-Elmer 3205 CLICKSIZE=4096, UNIX=/edition7
34# Perkin-Elmer all others, CLICKSIZE=2048, UNIX=/edition7
35CLICKSIZE=512
36eval $*
37
069b1bdb
JL
38if test -n "$UNIX"
39then
40 : User must have specified it already.
41elif test -r /vmunix
42then
43 UNIX=/vmunix
44 CLICKSIZE=512 # Probably VAX
45elif test -r /edition7
46then
47 UNIX=/edition7
48 CLICKSIZE=2048 # Perkin-Elmer: change to 4096 on a 3205
49elif test -r /unix
50then
51 UNIX=/unix # Could be anything
52fi
53
64d06f2f 54SIZE=0
6b2a673d 55# messages: probably the most transportable
b528bd5e 56if test -r /var/log/messages -a -s /var/log/messages
64d06f2f 57then
b528bd5e 58 SIZE=`grep avail /var/log/messages | sed -n '$s/.*[ ]//p'`
64d06f2f
KM
59fi
60
61if test 0$SIZE -le 0 # no SIZE in /usr/adm/messages
62then
63 if test -r $KMEM # Readable KMEM
64 then
64d06f2f
KM
65 if test -n "$UNIX"
66 then
67 SIZE=`echo maxmem/D | adb $UNIX $KMEM | sed -n '$s/.*[ ]//p'`
68 if test 0$SIZE -le 0
69 then
4eeb10d4 70 SIZE=`echo physmem/D | adb $UNIX $KMEM | sed -n '$s/.*[ ]//p'`
64d06f2f
KM
71 fi
72 SIZE=`expr 0$SIZE '*' $CLICKSIZE`
73 fi
74 fi
75fi
76
4eeb10d4
JL
77case $UNIX in
78 /vmunix) # Assume 4.2bsd: check for resource limits
79 MAXSIZE=`csh -c limit | awk 'BEGIN { MAXSIZE = 1000000 }
80/datasize|memoryuse/ && NF == 3 { if ($2 < MAXSIZE) MAXSIZE = $2 }
81END { print MAXSIZE * 1000 }'`
82 if test $MAXSIZE -lt $SIZE
83 then
84 SIZE=$MAXSIZE
85 fi
86 ;;
87esac
88
64d06f2f
KM
89if test 0$SIZE -le 0
90then
4eeb10d4 91 echo 0;exit 1
64d06f2f
KM
92else
93 echo $SIZE
94fi