Commit | Line | Data |
---|---|---|
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 | |
28 | KMEM=/dev/kmem # User needs read access to KMEM | |
29 | UNIX= | |
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 | |
35 | CLICKSIZE=512 | |
36 | eval $* | |
37 | ||
069b1bdb JL |
38 | if test -n "$UNIX" |
39 | then | |
40 | : User must have specified it already. | |
41 | elif test -r /vmunix | |
42 | then | |
43 | UNIX=/vmunix | |
44 | CLICKSIZE=512 # Probably VAX | |
45 | elif test -r /edition7 | |
46 | then | |
47 | UNIX=/edition7 | |
48 | CLICKSIZE=2048 # Perkin-Elmer: change to 4096 on a 3205 | |
49 | elif test -r /unix | |
50 | then | |
51 | UNIX=/unix # Could be anything | |
52 | fi | |
53 | ||
64d06f2f | 54 | SIZE=0 |
6b2a673d | 55 | # messages: probably the most transportable |
b528bd5e | 56 | if test -r /var/log/messages -a -s /var/log/messages |
64d06f2f | 57 | then |
b528bd5e | 58 | SIZE=`grep avail /var/log/messages | sed -n '$s/.*[ ]//p'` |
64d06f2f KM |
59 | fi |
60 | ||
61 | if test 0$SIZE -le 0 # no SIZE in /usr/adm/messages | |
62 | then | |
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 | |
75 | fi | |
76 | ||
4eeb10d4 JL |
77 | case $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 } | |
81 | END { print MAXSIZE * 1000 }'` | |
82 | if test $MAXSIZE -lt $SIZE | |
83 | then | |
84 | SIZE=$MAXSIZE | |
85 | fi | |
86 | ;; | |
87 | esac | |
88 | ||
64d06f2f KM |
89 | if test 0$SIZE -le 0 |
90 | then | |
4eeb10d4 | 91 | echo 0;exit 1 |
64d06f2f KM |
92 | else |
93 | echo $SIZE | |
94 | fi |