home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / util / compress / usermem.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1988-10-19  |  2.7 KB  |  95 lines

  1. #!/bin/sh -
  2. #
  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. #
  22. #    @(#)usermem.sh    5.5 (Berkeley) 10/15/88
  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.  
  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.  
  54. SIZE=0
  55. # messages: probably the most transportable
  56. if test -r /usr/adm/messages -a -s /usr/adm/messages
  57. then
  58.     SIZE=`grep avail /usr/adm/messages | sed -n '$s/.*[     ]//p'`
  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
  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
  70.         SIZE=`echo physmem/D | adb $UNIX $KMEM | sed -n '$s/.*[     ]//p'`
  71.         fi
  72.         SIZE=`expr 0$SIZE '*' $CLICKSIZE`
  73.     fi
  74.     fi
  75. fi
  76.  
  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.  
  89. if test 0$SIZE -le 0
  90. then
  91.     echo 0;exit 1
  92. else
  93.     echo $SIZE
  94. fi
  95.