v13i106: u386mon 1.12 part 04.04
wht at gatech.edu
wht at gatech.edu
Tue Jul 3 10:14:33 AEST 1990
Posting-number: Volume 13, Issue 106
Submitted-by: wht at gatech.edu@n4hgf.UUCP (Warren Tucker)
Archive-name: u386mon-1.12/part04
#!/bin/sh
# This is part 04 of u386mon.1.12
if touch 2>&1 | fgrep 'mmdd' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= nlsym.h ==============
echo "x - extracting nlsym.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > nlsym.h &&
X/*+-------------------------------------------------------------------------
X nlsym.h -- utility nlist - fast access to kernel /dev/kmem offsets
X ...!emory!n4hgf!wht
X
XThe nlsym file contains three records:
X1. struct stat unixstat - stat buffer from /unix at file creation time
X2. struct nlist nlsym - the structure of nlist'd information
X3. long unique - a unique identifier to help ensure correct nlsym length
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-27-1990-01:57-wht at n4hgf-1.10 - incorporate suggestions from alpha testers */
X/*:06-27-1990-01:55-wht at n4hgf-use 64 bits of unique check */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:26-r at n4hgf-version x0.12 seems bug free */
X/*:10-27-1988-11:07-wht-creation */
X
X#define UNIX_KERNEL "/unix"
X#define UNIX_NLSYM "/unix.nlsym"
X#define NLSYM_UNIQUE1 0x1BADD00DL
X#define NLSYM_UNIQUE2 0xDEADB1FFL
X
X#define Nindex_AVAILRMEM 0
X#define Nindex_AVAILSMEM 1
X#define Nindex_BDEVCNT 2
X#define Nindex_BDEVSW 3
X#define Nindex_BOOTINFO 4
X#define Nindex_CDEVCNT 5
X#define Nindex_CDEVSW 6
X#define Nindex_CFREE 7
X#define Nindex_CFREECNT 8
X#define Nindex_CFREELIST 9
X#define Nindex_CONSSW 10
X#define Nindex_CURPROC 11
X#define Nindex_DINFO 12
X#define Nindex_DSTFLAG 13
X#define Nindex_DUMPDEV 14
X#define Nindex_EMAP 15
X#define Nindex_FFREELIST 16
X#define Nindex_FILE 17
X#define Nindex_FMODCNT 18
X#define Nindex_FMODSW 19
X#define Nindex_FREEMEM 20
X#define Nindex_FSINFO 21
X#define Nindex_FSTYPSW 22
X#define Nindex_HZ 23
X#define Nindex_IDLESERVER 24
X#define Nindex_IFREELIST 25
X#define Nindex_INODE 26
X#define Nindex_KPTBL 27
X#define Nindex_LBOLT 28
X#define Nindex_LINECNT 29
X#define Nindex_LINESW 30
X#define Nindex_MAXCLICK 31
X#define Nindex_MAXMEM 32
X#define Nindex_MINFO 33
X#define Nindex_MOUNT 34
X#define Nindex_MSGLISTCNT 35
X#define Nindex_NFSTYP 36
X#define Nindex_NPTALLOCED 37
X#define Nindex_NPTFREE 38
X#define Nindex_NSERVERS 39
X#define Nindex_NSWAP 40
X#define Nindex_NSYSENT 41
X#define Nindex_OLDPROC 42
X#define Nindex_OLD_CURPROC 43
X#define Nindex_PANICSTR 44
X#define Nindex_PHYSMEM 45
X#define Nindex_PIPEDEV 46
X#define Nindex_PROC 47
X#define Nindex_RCINFO 48
X#define Nindex_ROOTDEV 49
X#define Nindex_RUNQ 50
X#define Nindex_SHLBINFO 51
X#define Nindex_SWAPDEV 52
X#define Nindex_SWPLO 53
X#define Nindex_SYSERR 54
X#define Nindex_SYSINFO 55
X#define Nindex_SYSSEGS 56
X#define Nindex_SYSWAIT 57
X#define Nindex_TIME 58
X#define Nindex_TIMEZONE 59
X#define Nindex_TTHIWAT 60
X#define Nindex_TTLOWAT 61
X#define Nindex_TUNE 62
X#define Nindex_U 63
X#define Nindex_USERTABLE 64
X#define Nindex_V 65
X#define Nindex_WIN_UBLK 66
X#ifdef M_UNIX
X#define Nindex_SIO_TTY 67
X#endif
X
X#define bootinfoaddr (nlsym[Nindex_BOOTINFO].n_value)
X#define freememaddr (nlsym[Nindex_FREEMEM].n_value)
X#define lboltaddr (nlsym[Nindex_LBOLT].n_value)
X#define maxmemaddr (nlsym[Nindex_MAXMEM].n_value)
X#define minfoaddr (nlsym[Nindex_MINFO].n_value)
X#define nswapaddr (nlsym[Nindex_NSWAP].n_value)
X#define physmemaddr (nlsym[Nindex_PHYSMEM].n_value)
X#define procaddr (nlsym[Nindex_PROC].n_value)
X#define sysinfoaddr (nlsym[Nindex_SYSINFO].n_value)
X#define tuneaddr (nlsym[Nindex_TUNE].n_value)
X#define vaddr (nlsym[Nindex_V].n_value)
X#ifdef M_UNIX
X#define sio_ttyaddr (nlsym[Nindex_SIO_TTY].n_value)
X#endif
X
X#ifdef DEFINE_NLSYM
Xstruct nlist nlsym[] =
X{
X { "availrmem" },
X { "availsmem" },
X { "bdevcnt" },
X { "bdevsw" },
X { "bootinfo" },
X { "cdevcnt" },
X { "cdevsw" },
X { "cfree" },
X { "cfreecnt" },
X { "cfreelist" },
X { "conssw" },
X { "curproc" },
X { "dinfo" },
X { "Dstflag" },
X { "dumpdev" },
X { "emap" },
X { "ffreelist" },
X { "file" },
X { "fmodcnt" },
X { "fmodsw" },
X { "freemem" },
X { "fsinfo" },
X { "fstypsw" },
X { "Hz" },
X { "idleserver" },
X { "ifreelist" },
X { "inode" },
X { "kptbl" },
X { "lbolt" },
X { "linecnt" },
X { "linesw" },
X { "maxclick" },
X { "maxmem" },
X { "minfo" },
X { "mount" },
X { "msglistcnt" },
X { "nfstyp" },
X { "nptalloced" },
X { "nptfree" },
X { "nservers" },
X { "nswap" },
X { "nsysent" },
X { "oldproc" },
X { "old_curproc" },
X { "panicstr" },
X { "physmem" },
X { "pipedev" },
X { "proc" },
X { "rcinfo" },
X { "rootdev" },
X { "runq" },
X { "shlbinfo" },
X { "swapdev" },
X { "swplo" },
X { "syserr" },
X { "sysinfo" },
X { "syssegs" },
X { "syswait" },
X { "time" },
X { "Timezone" },
X { "tthiwat" },
X { "ttlowat" },
X { "tune" },
X { "u" },
X { "usertable" },
X { "v" },
X { "win_ublk" },
X#ifdef M_UNIX
X { "sio_tty" },
X#endif
X { (char *)0 }
X};
X#else
Xextern struct nlist nlsym[];
X#endif
X
X/* vi: set tabstop=4 shiftwidth=4: */
SHAR_EOF
$TOUCH -am 0627015790 nlsym.h &&
chmod 0644 nlsym.h ||
echo "restore of nlsym.h failed"
set `wc -c nlsym.h`;Wc_c=$1
if test "$Wc_c" != "5457"; then
echo original size 5457, current size $Wc_c
fi
# ============= u386mon.h ==============
echo "x - extracting u386mon.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > u386mon.h &&
X/*+-------------------------------------------------------------------------
X u386mon.h
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-27-1990-01:57-wht at n4hgf-1.10 - incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:27-r at n4hgf-version x0.12 seems bug free */
X/*:06-20-1990-03:03-root at n4hgf-trick use_cp into making bright fgnd colors */
X/*:06-19-1990-21:35-wht-get ready for release */
X
X#ifndef M_SYSV /* for ISC */
X#define u_char unsigned char
X#define u_long unsigned long
X#endif
X
Xchar *getenv();
Xchar *strchr();
Xchar *strrchr();
X#ifdef __STDC__
Xvoid *malloc();
X#else
Xchar *malloc();
X#endif
X
X#define pW(pan) panel_window(pan)
X#define W WINDOW
X#define P PANEL
X
X/* color numbers for EGA/VGA */
X#ifdef COLOR_16_TERMINFO /* wht 16-color fgnd/bgnd terminfo */
X#define cHIBIT 8
X#define cBLK 0
X#define cBLU 1
X#define cGRN 2
X#define cCYN 3
X#define cRED 4
X#define cMAG 5
X#define cBRN 6
X#define cWHT 7
X#define cGRY (cBLK | cHIBIT)
X#define cLTB (cBLU | cHIBIT)
X#define cLTG (cGRN | cHIBIT)
X#define cLTC (cCYN | cHIBIT)
X#define cLTR (cRED | cHIBIT)
X#define cLTM (cMAG | cHIBIT)
X#define cYEL (cBRN | cHIBIT)
X#define cHIW (cWHT | cHIBIT)
X#else
X#define cBLK COLOR_BLACK
X#define cBLU COLOR_BLUE
X#define cGRN COLOR_GREEN
X#define cCYN COLOR_CYAN
X#define cRED COLOR_RED
X#define cMAG COLOR_MAGENTA
X#define cBRN COLOR_YELLOW
X#define cWHT COLOR_WHITE
X#define cGRY COLOR_BLACK
X#define cLTB COLOR_BLUE
X#define cLTG COLOR_GREEN
X#define cLTC COLOR_CYAN
X#define cLTR COLOR_RED
X#define cLTM COLOR_MAGENTA
X#define cYEL COLOR_YELLOW
X#define cHIW COLOR_WHITE
X#endif
X
X#define sTL 0xDA
X#define sTR 0xBF
X#define sBL 0xC0
X#define sBR 0xD9
X#define sLT 0xC3 /* left hand T */
X#define sRT 0xB4 /* right hand T */
X#define sVR 0xB3 /* vertical rule */
X#define sHR 0xC4 /* horizontal rule */
X
X/* color pairs */
X#ifdef COLOR_16_TERMINFO /* wht 16-color fgnd/bgnd terminfo */
X#define use_cp(win,cp) wattrset(win,COLOR_PAIR(cp))
X#else
X#define use_cp(win,cp) wattrset(win,COLOR_PAIR(cp) | ((cp >= cpLOW)?A_BOLD:0))
X#endif
X#define cpINFO 1 /* information field */
X#define cpHIGH 2 /* high/brk/pio */
X#define cpREVERSE 3 /* "reverse video" */
X/* color pairs >= cpLOW need A_BOLD when using standard ISO (non-wht) terminfo
X */
X#define cpLOW 4 /* low/user/iop */
X#define cpMED 5 /* medium/kernel/swap */
X#define cpBANNER 6 /* banner */
X#define cpLIT 7 /* field literals */
X
X#define MSG_TLY (LINES - 2)
X#define CMD_TLY (LINES - 1)
X#define LVMSG_Y MSG_TLY
X#define LVMSG_X 0
X
X#define CPUSCALE_TLY 1
X#define CPUSCALE_SX 13
X#define CPUSCALE_WIDTH 50
X
X#define WAITSCALE_TLY 5
X#define WAITSCALE_SX 13
X#define WAITSCALE_WIDTH 50
X
X/* Sysinfo/Minfo per second area */
X#define PER_SEC_TLY 9
X#define PER_SEC1_TLX 0
X#define PER_SEC2_TLX 18
X#define PER_SEC3_TLX 35
X#define PER_SEC4_TLX 51
X#define PER_SEC5_TLX 66
X
X/* extra info area */
X#define EXTRA_TLY 26
X#define EXTRA1_TLX 0
X#define EXTRA2_TLX 18
X#define EXTRA3_TLX 43
X#define EXTRA4_TLX 62
X
X#include "lint_args.h"
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of u386mon.h */
SHAR_EOF
$TOUCH -am 0627015790 u386mon.h &&
chmod 0644 u386mon.h ||
echo "restore of u386mon.h failed"
set `wc -c u386mon.h`;Wc_c=$1
if test "$Wc_c" != "3211"; then
echo original size 3211, current size $Wc_c
fi
# ============= renice/Makefile ==============
if test ! -d 'renice'; then
echo "x - creating directory renice"
mkdir 'renice'
fi
echo "x - extracting renice/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > renice/Makefile &&
X#+-------------------------------------------------------------------
X# Makefile for renice for SCO UNIX V/386
X# ...!emory!n4hgf!wht
X#--------------------------------------------------------------------
X#+:EDITS:*/
X#:06-25-1990-04:14-wht at n4hgf-1.03-better error handling
X#:06-21-1990-14:27-r at n4hgf-version x0.12 seems bug free
X#:06-19-1990-21:37-wht at n4hgf-get ready for 0.08 release
X
X#------------> CFLAGS
XCFLAGS = -c -Octl -DLINT_ARGS
X#CFLAGS = -c -O
X
X#------------> BINDIR
XBINDIR = /usr/local/bin
X
X#LDFLAGS = -s
X
X
X#handle Sys V make "feature" of using SHELL
XSHELL = /bin/sh
X
X#FCRC = fcrc -u $*.c ;
X.c.o:; $(FCRC) $(CC) $(CFLAGS) $*.c
X
XSRC = \
X renice.c
X
XRENICE_OBJ =\
X renice.o\
X ../libnlsym.o\
X libkmem-w.o
X
Xall: renice
X
X#must run as root
Xinstall: all
X mv renice $(BINDIR)
X chmod 4711 $(BINDIR)/renice
X chown root $(BINDIR)/renice
X @echo ' ';echo 'csh users rehash before executing'
X
Xrenice: $(RENICE_OBJ)
X $(CC) $(LDFLAGS) -o $@ $(RENICE_OBJ) $(LIB)
X
Xlibkmem-w.o: ../libkmem.c
X cc $(CFLAGS) -I .. -DKWRITE_NEEDED ../libkmem.c; mv libkmem.o libkmem-w.o
X
X../libnlsym.o: ../libnlsym.c
X cd ..;make libnlsym.o
X
Xclean:
X rm -f renice.o libkmem-w.o core
X
Xclobber: clean
X rm -f renice
X
SHAR_EOF
$TOUCH -am 0626155390 renice/Makefile &&
chmod 0644 renice/Makefile ||
echo "restore of renice/Makefile failed"
set `wc -c renice/Makefile`;Wc_c=$1
if test "$Wc_c" != "1186"; then
echo original size 1186, current size $Wc_c
fi
# ============= renice/renice.c ==============
echo "x - extracting renice/renice.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > renice/renice.c &&
X/*+-------------------------------------------------------------------------
X renice.c - UNIX 386 renice
X
X * This program was written by me, Mike "Ford" Ditto, and
X * I hereby release it into the public domain in the interest
X * of promoting the development of free, quality software
X * for the hackers and users of the world.
X *
X * Feel free to use, copy, modify, improve, and redistribute
X * this program, but keep in mind the spirit of this
X * contribution; always provide source, and always allow
X * free redistribution (shareware is fine with me). If
X * you use a significant part of this code in a program of
X * yours, I would appreciate being given the appropriate
X * amount of credit.
X * -=] Ford [=-
X *
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-26-1990-15:09-wht at n4hgf-adapt Ford's work to UNIX 386 */
X
X#include <stdio.h>
X#include <errno.h>
X#include <sys/types.h>
X#undef NGROUPS_MAX
X#undef NULL
X#include <sys/param.h>
X#include <sys/immu.h>
X#include <sys/region.h>
X#include <sys/proc.h>
X#include <sys/var.h>
X#include <nlist.h>
X#include "../nlsym.h"
X#include "../libkmem.h"
X#include "../libnlsym.h"
X
Xstruct var v;
Xstruct proc tproc;
Xint myuid;
Xchar *progname;
Xchar s128[128];
Xdaddr_t myreadcnt;
X
X/*+-------------------------------------------------------------------------
X leave_text(text,exit_code)
XIf exit_code == 255, do perror
X--------------------------------------------------------------------------*/
Xvoid
Xleave_text(text,exit_code)
Xchar *text;
Xint exit_code;
X{
X if(exit_code == 255)
X perror(text);
X else
X {
X fputs(text,stderr);
X fputs(text,stderr);
X }
X exit(exit_code);
X} /* end of leave */
X
X/* change the nice value of process `pid' based on 'value' and 'relative' */
Xrenice(pid,value,relative)
Xint pid;
Xint value;
Xint relative;
X{
X register i;
X int tmpnice;
X
X for(i = 0; i < v.v_proc; i++)
X {
X kread((caddr_t)&tproc,(daddr_t)((struct proc *)procaddr + i),
X sizeof(struct proc));
X if(tproc.p_pid == pid)
X {
X#ifdef DEBUG
X fprintf(stderr,"Found it! proc[%d], p_uid is %d\n",
X i,tproc.p_uid);
X
X fprintf(stderr,"Old p_nice was %d\n",tproc.p_nice);
X#endif /* DEBUG */
X
X tmpnice = tproc.p_nice;
X
X if(relative)
X tmpnice += value;
X else
X tmpnice = value;
X
X if(tmpnice >= 40)
X tmpnice = 40;
X if(tmpnice < 0)
X tmpnice = 0;
X
X#ifdef DEBUG
X fprintf(stderr,"New p_nice is %d\n",tmpnice);
X#endif /* DEBUG */
X
X if(
X#ifdef WHT
X (myuid && (myuid != 201))
X#else
X myuid
X#endif
X && ((myuid != tproc.p_uid) || (tmpnice < tproc.p_nice)))
X {
X errno = EACCES;
X sprintf(s128,"%s: can't renice process %d",progname,pid);
X perror(s128);
X return 1;
X }
X
X tproc.p_nice = tmpnice;
X
X kwrite((daddr_t)&((struct proc *)procaddr)[i]
X + ( ((caddr_t)&tproc.p_nice) - (caddr_t)&tproc ),
X (caddr_t)&tproc.p_nice,sizeof(tproc.p_nice));
X return(0);
X }
X }
X fprintf(stderr,"%s: process %d not found.\n",progname,pid);
X
X return(1);
X}
X
X/*+-------------------------------------------------------------------------
X usage()
X--------------------------------------------------------------------------*/
Xvoid
Xusage()
X{
X fprintf(stderr,"usage: %s [{+-}inc] [=prio] pid ...\n",progname);
X exit(-1);
X} /* end of usage */
X
X/*+-------------------------------------------------------------------------
X main(argc,argv)
X--------------------------------------------------------------------------*/
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X int status=0;
X int pid;
X int relative = 1;
X int value = 0;
X
X progname = *argv;
X if(argc < 2)
X usage();
X
X myuid = getuid();
X nlsym_read();
X kinit(1);
X kread((caddr_t)&v,vaddr,sizeof(v));
X
X while(++argv,--argc)
X {
X switch(**argv)
X {
X case '-':
X if(sscanf(*argv+1,"%d",&value) != 1)
X usage();
X relative = 1;
X break;
X case '+':
X if(sscanf(*argv+1,"%d",&value) != 1)
X usage();
X value = -value;
X relative = 1;
X break;
X case '=':
X if(sscanf(*argv+1,"%d",&value) != 1)
X usage();
X relative = 0;
X break;
X default:
X if(sscanf(*argv,"%d",&pid) != 1)
X usage();
X status += renice(pid,value,relative);
X }
X }
X
X exit(status);
X} /* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of renice.c */
SHAR_EOF
$TOUCH -am 0626171790 renice/renice.c &&
chmod 0644 renice/renice.c ||
echo "restore of renice/renice.c failed"
set `wc -c renice/renice.c`;Wc_c=$1
if test "$Wc_c" != "4189"; then
echo original size 4189, current size $Wc_c
fi
exit 0
---------------------------------------------------------------------
Warren Tucker, TuckerWare emory!n4hgf!wht or wht at n4hgf.Mt-Park.GA.US
Any perceptible delay will eventually get on your nerves. --Bob Hyers
More information about the Comp.sources.misc
mailing list