Awe13.219 net.sources utzoo!decvax!harpo!floyd!vax135!lime!we13!rjk Mon Apr 19 19:45:39 1982 MEMAP: 11/70 RealTime Memory Map /*********************************************************************** * 11/70 MEMAP - REAL TIME MEMORY MAP * FILE 1 of 5 - README *********************************************************************** */ Memap is an active real-time (?) UNIX memory map. It displays the locations of processes in memory, updating changes once per second. A DEC VT100 with advanced video option is required for this program. Memaptest is a little demo program for memap. It is compiled with separate I/D space. Read the comment lines in the makefile; they tell you how to make the files. When completed, type the following for a demonstration: for X in 1 2 3 do sleep 10 /etc/memaptest done & /etc/memap This starts three of the demo programs so that the shared text segment can be seen. When all but the last one dies, the shared text will start flashing, then it will disappear with the death of the last one. For more info: Randy King WECo-Montgomery 8=392-4556 (we13!rjk) /*********************************************************************** * 11/70 MEMAP - REAL TIME MEMORY MAP * FILE 2 of 5 - Makefile *********************************************************************** */ # # Memap Makefile: `Make' must be executed as root. # # Specify your system maximum memory in the command line as: # make MEMORY=XXXXXXX # Where the X's are the decimal number of bytes of physical REAL # memory (printed at boot time as: real mem=XXXXXXX bytes). The # default size will be 11/70 maximum of 4 Megabytes. # # NOTE: Edit `memap.c' and set the define NPROC to at least the # number of slots in your process table. Default is 150. # # INSDIR is the directory where memap will reside. Normally, this # is /etc to keep it out of the public eye, although the public # can still use it. If you change INSDIR, you might also change # the SYNOPSIS in the manual page `memap.1'. # # RJKing WECo-MG6565 Sep 1981 # INSDIR=/etc MEMORY=4194304L MANDIR=/usr/man/local/man1 all: memap memaptest memap: $(CC) -DOURM=$(MEMORY) -O -n -s memap.c -o memap @if mv $(INSDIR)/memap $(INSDIR)/OLDmemap 2>/dev/null; \ then echo $(INSDIR)/memap moved to $(INSDIR)/OLDmemap; \ fi mv memap $(INSDIR)/memap chown root $(INSDIR)/memap chgrp bin $(INSDIR)/memap chmod 4775 $(INSDIR)/memap cp memap.1 $(MANDIR)/memap.1 chown bin $(MANDIR)/memap.1 chgrp bin $(MANDIR)/memap.1 chmod 664 $(MANDIR)/memap.1 memaptest: $(CC) -O -n -s memaptest.c -o memaptest @if mv $(INSDIR)/memaptest $(INSDIR)/OLDmemaptest 2>/dev/null; \ then echo $(INSDIR)/memaptest move to $(INSDIR)/OLDmemaptest; \ fi mv memaptest $(INSDIR)/memaptest chown bin $(INSDIR)/memaptest chgrp bin $(INSDIR)/memaptest chmod 775 $(INSDIR)/memaptest /*********************************************************************** * 11/70 MEMAP - REAL TIME MEMORY MAP * FILE 3 of 5 - memap.c *********************************************************************** */ /* Memap - Real time (?) UNIX memory map. This program produces a * real time display of the active system memory as near as can be * obtained. It is restricted to the VT100 terminal with advanced * video. RJKing WECO-MG6565 Sep 1981 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define NROW 23 /* # of rows in display */ #define NCOL 13 /* # of columns in display */ #define VOID (char *)0 /* Char NULL pointer */ #define NPROC 150 /* MAIN: Dimension for proc slots */ #define MAXM 4194304L /* MAIN: Max 11/70 MAIN memory */ #ifndef OURM #define OURM 3145728L /* MAIN: Our maximum memory */ #endif #define CSIZ (132 /NCOL) /* SHOW: Column width */ #define NSIZ (CSIZ -1) /* SHOW: Max process name length */ #define DRAW 001 /* SHOW[what]: Draw grid ticks */ #define ERAS 002 /* SHOW[what]: Erase at [addr] */ #define PRNT 004 /* SHOW[what]: Print at [addr] */ #define KERN 010000 /* SHOW[mode]: This proc is kernel */ #define TEXT 020000 /* SHOW[slot]: This proc has sep I/D */ #define DATA 040000 /* UPDATE[what]: update non-text */ #define ENDM 0001 /* SHOW: Screen position is END mark */ #define PRCM 0002 /* SHOW: Screen position is process */ #define TXTM 0004 /* SHOW: Screen position is text */ #define PROC 0 /* MAIN: Index to nl struct */ #define SBUF 1 /* MAIN: Index to nl struct */ #define ENDT 2 /* MAIN: Index to nl struct */ #define UTXS 3 /* MAIN: Index to nl struct */ #define TXTT 4 /* MAIN: Index to nl struct */ #define VARA 5 /* MAIN: Index to nl struct */ #define USER 6 /* MAIN: Index to nl struct */ #define NNLE 7 /* MAIN: Number of namelist entries */ int tmem,catch(); /* Signal catching routine */ char position[NROW][NCOL]; /* "position occupied" flags */ long maxmem=OURM; /* Default screen resolution */ struct nlist nl[] = { { "_proc" }, { "_sabuf" }, { "_etext" }, { "tstart" }, { "_text" }, { "_v" }, { "_u" }, { "" } }; struct savp { char p_stat, p_flag; short p_pid; ushort p_addr, p_size; ushort x_size, x_caddr; char x_count; } savp[NPROC]; struct proc newp; struct text newt; struct var var; struct user ub; char *getenv(),*strcpy(),*malloc(),*strncpy(),*strcat(),*strncat(),*ctime(); long lseek(),atol(),time(); unsigned sleep(); extern (*signal())(); extern optind,errno; extern char *optarg; main(argc,argv) char *argv[]; { register int i,slot; register char *tp; int smem,umem; long t,addr,size; struct utsname uts; unsigned mode; if(strcmp(getenv("TERM"), "vt100") != 0) { fprintf(stderr, "Term not vt100\n"); exit(1); } uname(&uts); smem = open("/dev/mem", O_RDONLY); umem = open("/dev/mem", O_RDONLY); tmem = open("/dev/mem", O_RDONLY); if(smem MAXM || maxmem NPROC) { fprintf(stderr, "NPROC define must be at least %d\n", var.v_proc); exit(1); } if(NPROC > var.v_proc +25) { fprintf(stderr, "NPROC define wasting memory; should be around %d\n", var.v_proc); sleep(5); } show(DRAW, VOID, 0L, 0L, NULL); show(PRNT, "Proctbl", (long)nl[PROC].n_value, 0L, KERN); show(PRNT, "_sabufs", (long)nl[SBUF].n_value, 0L, KERN); show(PRNT, "EndOfText", (long)nl[ENDT].n_value, 0L, KERN); show(PRNT, uts.sysname, (long)nl[UTXS].n_value, 0L, KERN); addr = (long)(nl[USER].n_value + USIZE *64); show(PRNT, "Stack_Top", addr, 0L, KERN); i = nice(0); nice(-i); for(;;) { if(lseek(smem, (long)nl[PROC].n_value, 0) = 1)) { addr = ctob((long)savp[slot].x_caddr); size = ctob((long)savp[slot].x_size); show(ERAS, VOID, addr, size, NULL); savp[slot].x_count = 0; } } if((newp.p_flag &SLOAD) == 0) { clearout(slot); continue; } if(newp.p_addr) { addr = ctob((long)newp.p_addr); size = ctob((long)newp.p_size); mode = (unsigned)(newp.p_flag &0377); mode |= ((newp.p_stat <<8) MEG) IF(SROW="=" GETEXTDATA()) PRINTF("M"); PRINTF("\33(B\33[24H\33[M"); STATIC -3) ECOL, / PRINTF("\33[24;59H%S", < +1); &07400); MODE="TEXT;" I,SWAP="0;" SROW, PRINTF("\33<\33[?3H"); 0) SHOW(PRNT, UPDATE(TEXT, UNSIGNED CHAR SROW<="NROW;" ELSE \33[7MSPECIAL\33[M *(TP+19)="NULL;" ECPOS; 1) FLAG="(char)(mode" { } USER FATALERR("SEEK (CHAR PRINTF("%D ADDR, NAME, (%.2F ++SCOL) PRINTF("T\B\33D"); SRPOS, , TICKS, (DOUBLE)MAXMEM /1048576.0); PRINTF( SHOW(WHAT, &07400) &0377); BYTES/TICK INT SLEEP(1); TICKS; ADDR="ctob((long)newt.x_caddr);" TICKS="(int)" *NAME; MODE); && MODE) &DRAW) IF(UB.U_TSIZE MODE; TO TP="ctime(&t);" IF(WHAT LONG SCPOS, (NCOL SCOL, SLOT); EROW, SCOL<="NCOL;" BLOCK"); UPDATE(DATA, TIME(&T); \33[4MLOCKED\33[M \33[1MRUNNABLE\33[M\33(0"); SIZE, (MAXMEM PNAM[32],FLAG,STAT; SIZE; CHECK; IF(READ(UMEM, ); PRINTF( STAT="(char)((mode" ((LONG)(NCOL *(SCOL REGISTER PRINTF("\33[1;%DH", *NROW))); IF(LSEEK(UMEM, FATALERR("READ FOR(SROW="1;" \33[1;7MTEXT\33[M SIZEOF(UB)) PRINTF("L\B\33D"); *)&UB, FOR(SCOL="1;" ++SROW) NROW) UB.U_COMM, TP+11); SIZE="ctob((long)newt.x_size);" PRINTF("\33[2J\33[24H\33#6"); -1) ERPOS,>>8); check = (addr /(long)ticks) +1L; if(check > (long)(NROW *NCOL)) return; srow = (int)check; check = ((addr +size) /(long)ticks) +1L; if(check > (long)(NROW *NCOL)) return; erow = (int)check; for(scol=0; srow>NROW; ++scol) srow -= NROW; srpos = srow -1; scpos = scol; scol = (scol *CSIZ) +2; for(ecol=0; erow>NROW; ++ecol) erow -= NROW; erpos = erow -1; ecpos = ecol; ecol = (ecol *CSIZ) +2; if(*name == NULL) { if(newp.p_pid == 0) name = "swapper"; else { name = "SWAPPING"; ++swap; } } if(what &ERAS) { printf("\33[%d;%dH\33[%d;%dH", srow, scol, srow, scol); for(i=0; i
This Usenet Oldnews Archive article may be copied and distributed freely, provided:

1. There is no money collected for the text(s) of the articles.
2. The following notice remains appended to each copy:

The Usenet Oldnews Archive: Compilation Copyright© 1981, 1996
Bruce Jones, Henry Spencer, David Wiseman.


Goto NEXT article in NET.sources Newsgroup
Return to NET.sources index
Return to the Usenet Oldnews Archive index ----------------------------------------------------------------- gopher://quux.org/ conversion by John Goerzen of http://communication.ucsd.edu/A-News/ This Usenet Oldnews Archive article may be copied and distributed freely, provided: 1. There is no money collected for the text(s) of the articles. 2. The following notice remains appended to each copy: The Usenet Oldnews Archive: Compilation Copyright (C) 1981, 1996 Bruce Jones, Henry Spencer, David Wiseman.