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 <STDIO.H>
#include <FCNTL.H>
#include <A.OUT.H>
#include <SYS/UTSNAME.H>
#include <SYS/PARAM.H>
#include <SYS/TYPES.H>
#include <SYS/SYSMACROS.H>
#include <SYS/TEXT.H>
#include <SYS/FILE.H>
#include <SYS/INODE.H>
#include <SYS/PROC.H>
#include <SYS/TTY.H>
#include <SYS/DIR.H>
#include <SYS/SIGNAL.H>
#include <SYS/USER.H>
#include <SYS/VAR.H>
#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<NSIZ; MULTIPLY KERNEL (SOMETIMES) IF(NEWP.P_FLAG SYNOPSIS DISPLAYED, BUT THINGS SHOULD BUGS );
POSITION[ERPOS][ECPOS] = 0;
}
}
IF(WHAT &PRNT)
{ IF((MODE &TEXT) && POSITION[SRPOS][SCPOS] == TXTM)
RETURN;
*PNAM = NULL;
IF(FLAG &SLOCK)
STRCAT(PNAM, EXIT(0); BECAUSE {NODENAME}\^ THESE MEMSIZE ADDRESSABLE UNLESS GOES. !="0)" SAVP[SLOT].X_COUNT="0;" (_PROC) CALLED REPRESENT. WHOSE ( ) * + SAVP[SLOT].P_SIZE="0;" , \33[1;7M - SAVP[SLOT].P_PID="0;" . ECOL, (TOPOFSTACK) .B 1 `K' 4 5 PRESENCE /* ; < PRINTF(" MAP IF(POSITION[ERPOS][ECPOS]="=" NAME A *)&NEWT, PRE-DEFINED DESCRIPTION EXTRA DEFAULT MODE CHANGE &TEXT)?TXTM:PRCM; MAY FOR TWO. ETC. K M .PP NOT SROW, LINKED EXIT(1); 0) [ GETEXTDATA() ACTIVE ] NO CHAR CLICKS) MID-SWAP ONE WHILE(MALLOC(512) \33[4M"); DISPLAYS SECOND. I.E. TWICE. 0: THAT'S TALK DEC ADMINISTRATOR. REMEMBER DISCLAIMED USED WHEN `M' OF || 11/70 { REVERSE } ON VALUE DUE USER NEVER OR .BR SWAPPED. FATALERR("SEEK IF((MODE (CHAR 15 2400 PRINTF("\33[24H\33[2K"); IF(NEWP.P_ADDR SYMBOLS FATALERR(ERRMS) MARK NAME, TIME DEFINED OVERRIDDEN ARE: BELOW: SIGNAL(SIG, PROCESSES ALL CONVERSIONS PUTCHAR(7); \33[1M -T\^ WITH NEWT.X_SIZE="=" PRINTF("~"); THOSE MEMORY, NAMED JUST MEMORY. .SH \33[M SWAG: CONFUSING RESPECTIVELY. USIZE SRUN) IF(STAT="=" AS MEMORY; SHOWS SEPARATE MADE (_U FAIL BAUD CAUGHT DATA) PRINTF("\33[7M"); ADDRESSING EARLIER BE ++I) SIZEOF(NEWT)) FIRST .TH SAVP[SLOT].P_FLAG="0;" THAT WAY CLEAROUT(SLOT) .TP AND -M\^ OPTION TWO BY I/D THEIR CASE &KERN) STRNCAT(PNAM, SWAPPABLE THE SPECIFICATION TIKSIZE VT100'S. SWITCH(FORK()) NSIZ); SWAPPING INCORRECT |SSPART)) INT KNOWN TABLE"); PROCTBL\^ I<VAR.V_TEXT; -MMEMSIZE FORK(2) SLEEP(1); ADVANCED SOMETIMES PROGRAMS. IF(READ(TMEM, DOTS SH HAS TYPE SO SPEAK. IF(NEWT.X_COUNT TEXT SYSTEM RUNNABLE. PRINTF("\33[%D;%DH\33[%D;%DH%S", NUMBER IF(NEWP.P_STAT && SAMEPROC(SLOT) START KILO IF(LSEEK(TMEM, STACK ABOUT DIRECT PERROR("FORK"); DEFAULT: FILE BOLD TO POSITION[SRPOS][SCPOS]="(mode" HAVE CURRENTLY ED POINT IF(WHAT="=" ABOVE *ARGV[]; USUALLY MEMAP ANOTHER PS(1), NEWP.P_ADDR="0;" LOCKED </PRE SAVP[SLOT].X_SIZE="0;" /*********************************************************************** SAVP[SLOT].X_CADDR="0;" BELOW UPDATING THEM. SCOL, PRINTF("\33[?3L"); UNDERSCORED HIGH REAL WAYS SLOW UP CERTAIN POSITION[ERPOS][ECPOS]="ENDM;" EROW, PRINTF("\33(0\33[%D;%DH\33[%D;%DH", (LONG)NL[TXTT].N_VALUE, TICK SAVP[SLOT].P_ADDR="0;" PERROR(ERRMS); MEMAP.1 RUNNING. PNAM); MOMENT DISPLAY ARE MEMORY SENT 1048576, OCCASION, BREAK; \33[7M MAIN 1024 );
POSITION[SRPOS][SCPOS] = 0;
IF(POSITION[ERPOS][ECPOS] == ENDM)
{ PRINTF( IF(NEWP.P_SIZE MEMAP\^ /ETC/MEMAP ANSI EXIT(ERRNO); BUFFERS TIKSIZE. ONCE, (TSTART) SYMBOL VIDEO FOR(I="0;" IF(MODE RETURN(0); _SABUFS\^ SUFFIXED AVAILABLE (_SABUF) ); REGISTER MEGA, SEGMENTS BYTES MEMSIZE. DURING SORRY, ENDOFTEXT\^ LOCATIONS SPACE ACTIVITY OTHER. EACH FATALERR("READ WILL */ SMALL CURSOR MAKE PROCESS I; ADDRESS CALL. STRCAT(PNAM, \33[%D;%DH\33[%D;%DH", CAN NEWP.P_STAT &TEXT) RESIDING UPDATE(WHAT,SLOT) IN APPEAR WHILE BEEN IS RETURN(1); IT PRINTF("\33[1M"); CHARACTERS MEMAPTEST.C SWAP) SIG_IGN); UNIX SCALE TABLE OVERWRITTEN MUST IF(NEWP.P_PID EVERY SAVP[SLOT].P_STAT="0;" RSH TEXT) *MALLOC(); MAIN(ARGC,ARGV) UB.U_TSIZE) TOP TEXT. SYMBOLS. END THIS SIZE &(SSWAP AGAIN ONLY IMAGE I<NSIZ; -TTIKSIZE *********************************************************************** ECOL); EXIT(SIG); LOCAL *ERRMS; PRECEDING SUCH FLOATING CATCH(SIG) APPEARING -1: PRINTF("\33(B\33[M"); (_ETEXT) VT100 RED DISPLAYED>
<HR>
This Usenet Oldnews Archive
article may be copied and distributed freely, provided:
<P>
1. There is no money collected for the text(s) of the articles.
<BR>
2. The following notice remains appended to each copy:
<P>
<EM>The Usenet Oldnews Archive: Compilation Copyright© 1981, 1996
<BR> Bruce Jones, Henry Spencer, David Wiseman.</EM>
<P>
<HR>
Goto <A HREF="82.04.20_ucbarpa.1178_net.sources.html">NEXT</A> article in NET.sources Newsgroup
<BR>Return to <A HREF="NET.sources-index.html">NET.sources index</A>
<BR>Return to the
<A HREF="../index.html">Usenet Oldnews Archive index</A>
</HTML>
-----------------------------------------------------------------
gopher://quux.org/ conversion by John Goerzen <
[email protected]>
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.