home *** CD-ROM | disk | FTP | other *** search
- Xref: wupost alt.sources:3885 comp.unix.xenix.sco:4067
- Path: wupost!cs.utexas.edu!chinacat!chip
- From: chip@chinacat.unicom.com (Chip Rosenthal)
- Newsgroups: alt.sources,comp.unix.xenix.sco
- Subject: freemem - report memory usage statistics for SCO XENIX
- Message-ID: <1991Aug23.001931.13907@chinacat.unicom.com>
- Date: 23 Aug 91 00:19:31 GMT
- Followup-To: comp.unix.xenix.sco
- Organization: Unicom Systems Development, Inc.
- Lines: 297
-
- This utility is a little hack for SCO XENIX/386. It reports main
- memory and swap memory usage. I'd rather have sar, but this will
- do in a pinch.
-
-
- #! /bin/sh
- # this is a "shar" archive - run through "/bin/sh" to extract 3 files:
- # README freemem.c freemem.1
- # Wrapped by chip@chinacat on Thu Aug 22 19:16:43 CDT 1991
- # Unpacking this archive requires: sed test wc (possibly mkdir)
- # Existing files will not be clobbered unless "-c" is specified on the cmd line.
- if test -f README -a "$1" != "-c" ; then
- echo "README: file exists - will not be overwritten"
- else
- echo "x - README (file 1 of 3, 933 chars)"
- sed -e 's/^X//' << 'END_OF_FILE_README' > README
- X
- Xfreemem - report memory usage statistics for SCO XENIX.
- X
- XRun without any arguments, it produces a report such as:
- X
- X $ freemem
- X memory: 9172KB avail, 5164KB used swap: 8192KB avail, 0KB used
- X
- XIf a sampling interval is specified, it produces results such as:
- X
- X $ freemem 30
- X # physmem maxmem availmem usedmem totswp availswp usedswp
- X 14336 11940 9532 4804 8192 8192 0
- X 14336 11940 9116 5220 8192 8192 0
- X 14336 11940 8868 5468 8192 8192 0
- X 14336 11940 8656 5680 8192 8192 0
- X
- XThis utility needs read access to both /xenix and /dev/kmem - thus
- Xwill probably have to be installed setuid to `sysinfo'. It has been
- Xtested on SCO XENIX/386 2.3.3.
- X
- XWell...it ain't sar - but we gotta make due...
- X
- XChip Rosenthal
- XUnicom Systems Development, Inc.
- X<chip@chinacat.unicom.com>
- X
- X@(#) README 1.1 91/08/22 19:16:17
- X
- END_OF_FILE_README
- size="`wc -c < README`"
- if test 933 -ne "$size" ; then
- echo "README: extraction error - got $size chars"
- fi
- fi
- if test -f freemem.c -a "$1" != "-c" ; then
- echo "freemem.c: file exists - will not be overwritten"
- else
- echo "x - freemem.c (file 2 of 3, 3329 chars)"
- sed -e 's/^X//' << 'END_OF_FILE_freemem.c' > freemem.c
- X#ifndef lint
- Xstatic char SCCSID[] = "@(#) freemem.c 1.1 91/08/22 19:16:17";
- X#endif
- X
- X/*
- X * freemem - report memory usage statistics for SCO XENIX.
- X *
- X * Chip Rosenthal
- X * Unicom Systems Development, Inc.
- X * <chip@chinacat.unicom.com>
- X *
- X * Edit at tabstops=4.
- X */
- X
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <a.out.h>
- X#include <sys/param.h>
- X#include <sys/sysmacros.h>
- X
- X#define USAGE "usage: %s [-c corefile] [-n namelist] [sample_interval]\n"
- X#define KERNEL "/xenix"
- X#define KMEM "/dev/kmem"
- X#define KB(X) (ctob(X)/1024)
- X#define TRUE 1
- X#define FALSE 0
- X
- X#define V_AVAILMEM 0
- X#define V_MAXMEM 1
- X#define V_PHYSMEM 2
- X#define V_AVAILSWP 3
- X#define V_TOTSWP 4
- X
- Xstruct xlist v[] = {
- X { 0, 0, 0L, "_availmem" },
- X { 0, 0, 0L, "_maxmem" },
- X { 0, 0, 0L, "_physmem" },
- X { 0, 0, 0L, "_availswp" },
- X { 0, 0, 0L, "_totswp" },
- X { 0, 0, 0L, (char *)0 },
- X};
- X
- X
- Xchar *Kernel = KERNEL;
- Xchar *Kmem = KMEM;
- X
- Xvoid ksample();
- Xvoid kread();
- X
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int availmem, maxmem, physmem, availswp, totswp;
- X int interval, fd, line, i;
- X extern int optind;
- X extern char *optarg;
- X
- X while ((i = getopt(argc, argv, "c:n:")) != EOF) {
- X switch (i) {
- X case 'c':
- X if (getuid() != 0) {
- X fprintf(stderr, "%s: '-c' restricted to root\n", argv[0]);
- X exit(1);
- X }
- X Kmem = optarg;
- X break;
- X case 'n':
- X if (getuid() != 0) {
- X fprintf(stderr, "%s: '-n' restricted to root\n", argv[0]);
- X exit(1);
- X }
- X Kernel = optarg;
- X break;
- X default:
- X fprintf(stderr, USAGE, argv[0]);
- X exit(1);
- X }
- X }
- X
- X switch (argc-optind) {
- X case 0:
- X interval = 0;
- X break;
- X case 1:
- X if ((interval = atoi(argv[optind])) <= 0) {
- X fprintf(stderr, "%s: bad sample interval '%s'\n",
- X argv[0], argv[optind]);
- X exit(1);
- X }
- X break;
- X default:
- X fprintf(stderr, USAGE, argv[0]);
- X exit(1);
- X }
- X
- X if (xlist(Kernel, v) != 0) {
- X perror(Kernel);
- X exit(1);
- X }
- X if ((fd = open(Kmem, O_RDONLY)) < 0) {
- X perror(Kmem);
- X exit(1);
- X }
- X
- X if (interval == 0) {
- X ksample(fd, &maxmem, &physmem, &availmem, &availswp, &totswp);
- X printf(
- X "memory: %dKB avail, %dKB used swap: %dKB avail, %dKB used\n",
- X KB(availmem), KB(physmem-availmem),
- X KB(availswp), KB(totswp-availswp));
- X (void) close(fd);
- X exit(0);
- X }
- X
- X line = 0;
- X for (;;) {
- X
- X ksample(fd, &maxmem, &physmem, &availmem, &availswp, &totswp);
- X
- X if (line++ % 22 == 0) {
- X printf("# %8s %8s %8s %8s %8s %8s %8s\n",
- X "physmem", "maxmem", "availmem", "usedmem",
- X "totswp", "availswp", "usedswp"
- X );
- X }
- X
- X printf(" %8d %8d %8d %8d %8d %8d %8d\n",
- X KB(physmem), KB(maxmem), KB(availmem), KB(physmem-availmem),
- X KB(totswp), KB(availswp), KB(totswp-availswp));
- X
- X (void) sleep(interval);
- X
- X }
- X
- X (void) close(fd);
- X exit(0);
- X /*NOTREACHED*/
- X}
- X
- Xvoid ksample(fd, maxmem, physmem, availmem, availswp, totswp)
- Xint fd;
- Xint *maxmem, *physmem, *availmem, *availswp, *totswp;
- X{
- X kread(fd, v[V_MAXMEM].xl_value, (char *)maxmem, sizeof(int));
- X kread(fd, v[V_PHYSMEM].xl_value, (char *)physmem, sizeof(int));
- X kread(fd, v[V_AVAILMEM].xl_value, (char *)availmem, sizeof(int));
- X kread(fd, v[V_AVAILSWP].xl_value, (char *)availswp, sizeof(int));
- X kread(fd, v[V_TOTSWP].xl_value, (char *)totswp, sizeof(int));
- X}
- X
- X
- Xvoid kread(fd, pos, ptr, nbyte)
- Xint fd;
- Xlong pos;
- Xchar *ptr;
- Xunsigned nbyte;
- X{
- X if (lseek(fd, pos, 0) < 0 || read(fd, ptr, nbyte) != nbyte) {
- X perror(Kmem);
- X exit(1);
- X }
- X}
- X
- END_OF_FILE_freemem.c
- size="`wc -c < freemem.c`"
- if test 3329 -ne "$size" ; then
- echo "freemem.c: extraction error - got $size chars"
- fi
- fi
- if test -f freemem.1 -a "$1" != "-c" ; then
- echo "freemem.1: file exists - will not be overwritten"
- else
- echo "x - freemem.1 (file 3 of 3, 1249 chars)"
- sed -e 's/^X//' << 'END_OF_FILE_freemem.1' > freemem.1
- X.\" @(#) freemem.1 1.1 91/08/22 19:16:17
- X.TH FREEMEM 1L
- X.SH NAME
- Xfreemem - Display system memory and swap usage.
- X.SH SYNTAX
- X.B freemem
- X[
- X.B \-c
- Xcorefile ] [
- X.B \-n
- Xnamelist ] [ sample_interval ]
- X.SH DESCRIPTION
- X.I Freemem
- Xdisplay statistics on system main and swap memory usage. If a
- X.I sample_interval
- Xin seconds is given, then
- X.I freemem
- Xruns continuously providing a measurement at the specified intervals.
- X.P
- XAll values are reported in kilobytes. The following items are reported:
- X.IP physmem 12
- XThe physical memory in the system.
- X.IP maxmem 12
- XThe amount of memory available to user processes. The difference between
- X.I physmem
- Xand
- X.I maxmem
- Xis the amount of memory used by the kernel code and data.
- X.IP availmem 12
- XThe amount of memory currently unused.
- X.IP usedmem 12
- XThe amount of memory currently in use by the kernel and user processes.
- X.IP totswp 12
- XThe size of the swap disk division.
- X.IP availswp 12
- XThe amount of swap currently unused.
- X.IP usedswp 12
- XThe amount of swap currently in use.
- X.SH FILES
- X/xenix
- X.br
- X/dev/kmem
- X.SH SEE ALSO
- Xps(C), vmstat(C)
- X.SH BUGS
- XSome command line options are restricted to the root user for security
- Xreasons.
- X.SH AUTHOR
- XChip Rosenthal
- X.br
- XUnicom Systems Development, Inc.
- X.br
- X<chip@chinacat.unicom.com>
- END_OF_FILE_freemem.1
- size="`wc -c < freemem.1`"
- if test 1249 -ne "$size" ; then
- echo "freemem.1: extraction error - got $size chars"
- fi
- fi
- echo "done - 3 files extracted"
- exit 0
- --
- Chip Rosenthal 512-482-8260 | Lotus 1-2-3 for UNIX...it's a product
- Unicom Systems Development | you don't have to support.
- <chip@chinacat.Unicom.COM> | - recent Lotus 1-2-3 advert
-