pstat.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 1,614 行 · 第 1/3 页
C
1,614 行
#ifndef lintstatic char *sccsid = "@(#)pstat.c 4.5 (ULTRIX) 3/7/91";#endif/************************************************************************ * * * Copyright (c) 1988, 1990 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* ------------------------------------------------------------------------ * Modification History: /usr/src/etc/pstat.c * * 14 Nov 90 -- paradis * Added -v flag to display vector processes. * * 18 Sept 90 -- Philip C. Gapuz Te * Added scc_tty to name list for 3MIN serial line driver. * * 5 June 90 - Kuo-Hsiung Hsieh * Added mdc_tty name list for mipsmate serical line driver. * * 12 Jan 90 -- jaa * added reserved virtual address field to show swap * thats reserved but not allocated * * 08 Dec 89 -- sekhar * Fixed the following: * 1. Complete rewrite of doswap() code to handle dynamic swap changes * Dynamic swap useage is now tracked in a kernel data structure * swapu which is read here. * 2. print usage information when no parameters are specified to * the pstat command. * 3. modify klseek to work on mips. * 4. fixed to work with new pte layout on mips. * * 12 Jun 89 -- gg * Modified routine doswap() to reflect the dynamic swap changes. * Also modified doproc() routine to print the address of the * data and stack segment dmap structures. * * 12 Oct 88 - Tim Burke * Print out stats on firefox driver for the -t option. * * 6 Sep 88 -rnf * Added exit status of 0 on successful completion * * 9 Jun 88 * Bugs fixes to doswap * * 12 Apr 88 -jaa * Added check for errors on calloc()'s * Fixed printing of text information now tha text is km_alloc'd * * 03 Mar 88 -- Tim Burke * Added ability to print out terminal status for lat lines. Also added * checks for line disciplines TERMIODISC and SLPDISC. * Display the following tty flag: TS_OABORT. * * 2 Jun 88 -- Tim Burke * Added "-l" option to print out smp lock contention statistics. * This is only useful when the kernel has been compiled with SMP_STAT * defined. * * 24 Feb 88 -- depp * Remove reference to argdev in doswap() as argdev is now km_alloc'ed. * Added "swap configured" line to -s option. * * 23 Dec 87 -- Tim Burke * Added CLKT functionality for pstat -p. Also added TTYP field to * pstat -p because this field has been moved from the u struct to * the proc struct. * * 29 Jan 87 -- Marc Teitelbaum * Check for INUSE flag on inode, display as "I". Check for * FBLKINUSE on file flags, display as "B". Add checks for * following tty flags: * TT_STOP - 'S' * TT_INUSE - 'I' * TT_ONDELAY - 'D' * TT_IGNCAR - 'G' * TT_NBIO - 'N' * TT_ASYNC - 'Z' * * * 26 Jan 86 -- depp * Changed method that text swap space is calculated, do to the * changes in text table allocation/deallocation. The text table * allocation/deallocation changes also made changes to dotext(). * * 4 Dec 86 -- Tim burke * Added support for dmb driver as part of the pstat -t option. * * 15 Sep 86 -- bglover * Change refs to x_iptr to x_gptr (text.h change) * * 22 Aug 86 -- fred (Fred Canter) * Added support for VAXstar and MICROVAX 1800 serial line * device drivers to the pstat -t option. The ss device is * like the dzq11 and the sh is like an 8 line dhu11. * * 8 Apr 86 -- depp * Removed reference to u.u_exdata, as it no longer exists * * 14 Oct 85 -- rr * Fixed the handling of the -u ubase option. First problem * was that the assumption was made that the UPAGES+CLSIZE * preallocated 512 byte pages were contiguous and they are not. * Stole the code from ps.c to read in each CLICK (1024 presently) * and modified ps.c to print out the page table page frame * so that all we do in pstat.c is lseek and back up exactly * UPAGES+CLSIZE pte's, read the pte's, and then get each page * one click at a time. Hopefully, this extends the life of this routine. * Also, added new fields to the printout so that all fields are * now dumped by the pstat -u ubase option. * * 23 Feb 84 -- jmcg * Fixed -k flag handling. Now that bufpages are allocated * sparsely in virtual space to system buffers, there is no * longer a simple mapping between kernel virtual addresses * and physical memory. /dev/kmem provides this mapping when * running on a live system, but pstat must decipher the system * page table itself when running against a vmcore. These changes * were originally made and tested around 24 Jan 84. They are * almost identical to those provided over the Usenet by A R White * from University of Waterloo (newsgroup net.bugs.4bsd * <6927@watmath.UUCP> 17 Feb 1984). * * 23 Feb 84 --jmcg * Derived from 4.2BSD, labeled: * pstat.c 4.22 (Berkeley) 6/18/83 * with an update obtained by aps from ucbmonet. He updated the * sccsid to read: * *sccsid = "@(#)pstat.c 1.4 (Ultrix 1.0) (from 4.24 Berkeley) 2/24/84" * but lost the date. * * ------------------------------------------------------------------------ *//* * Print system stuff */#define mask(x) (x&0377)#define clear(x) ((int)x&0x7fffffff)#include <sys/param.h>#include <sys/dir.h>#define KERNEL#include <sys/file.h>#undef KERNEL#include <sys/user.h>#include <sys/proc.h>#include <sys/text.h>#include <sys/gnode.h>#include <sys/map.h>#include <sys/ioctl.h>#include <sys/tty.h>#include <sys/conf.h>#include <sys/vm.h>#include <sys/time.h>#include <nlist.h>#include <machine/pte.h>#ifdef vax#include <machine/vectors.h>#endif /* vax */#include <sys/ipc.h>#include <sys/shm.h>#undef SMP_STATchar *fcore = "/dev/kmem";char *fmem = "/dev/mem";char *fnlist = "/vmunix";int fc, fm;struct nlist nl[] = {#define SGNODE 0 { "_gnode" },#define STEXT 1 { "_text" },#define SPROC 2 { "_proc" },#define SDZ 3 { "_dz_tty" },#define SNDZ 4 { "_dz_cnt" },#define SKL 5 { "_cons" },#define SFIL 6 { "_file" },#define USRPTMA 7 { "_Usrptmap" },#define USRPT 8 { "_usrpt" },#define SWAPMAP 9 { "_swapmap" },#define SDH 10 { "_dh11" },#define SNDH 11 { "_ndh11" },#define SNPROC 12 { "_nproc" },#define SNTEXT 13 { "_ntext" },#define SNFILE 14 { "_nfile" },#define SNGNODE 15 { "_ngnode" },#define SNSWAPMAP 16 { "_nswapmap" },#define SPTY 17 { "_pt_tty" },#define SNSWDEV 18 { "_nswdev" },#define SSWDEVT 19 { "_swdevt" },#define SSYSMAP 20 { "_Sysmap" },#define SSYSSIZE 21 { "_Syssize" },#define SNPTY 22 { "_nNPTY" },#define SDHU 23 { "_dhu11" },#define SNDHU 24 { "_ndhu11"},#define SDMF 25 { "_dmf_tty"},#define SNDMF 26 { "_ndmf" },#define SDMZ 27 { "_dmz_tty" },#define SNDMZ 28 { "_ndmz" },#define SSS 29 { "_ss_tty" },#define SNSS 30 { "_ss_cnt" },#define SSH 31 { "_sh_tty" },#define SNSH 32 { "_sh_cnt" },#define SDMB 33 {"_dmb_tty"},#define SNDMB 34 {"_ndmb"},#define SLAT 35 {"_lata"},#define SNLAT 36 {"_nLAT1"},#define SSMEM 37 {"_smem"},#define SSMINFO 38 {"_sminfo"},#define SNLKDMB 39 {"_lk_dmb"},#define SNCFREE 40 {"_cfreelist"},#define SPROC_BITMAP 41 {"_proc_bitmap"},#define SFC 42 {"_fc_tty"},#define SNFC 43 {"_fc_cnt"},#define SSWAPFRAG 44 {"_swapfrag"},#define SSWAPU 45 {"_swapu"},#define AVAILVAS 46 {"_availvas"},#define SDC 47 {"_dc_tty"},#define SNDC 48 {"_dc_cnt"},#define SMDC 49 {"_mdc_tty"},#define SNMDC 50 {"_mdc_cnt"},#define SSCC 51 {"_scc_tty"},#define SNSCC 52 {"_scc_cnt"}, { "" }};struct ttytype { char *name; int ttybase; int nttys;} ttytypes[] = { { "dz", SDZ, SNDZ }, { "ss", SSS, SNSS }, { "dh", SDH, SNDH }, { "dhu", SDHU, SNDHU }, { "sh", SSH, SNSH }, { "dmf", SDMF, SNDMF }, { "dmz", SDMZ, SNDMZ }, { "dmb", SDMB, SNDMB }, { "fc", SFC, SNFC }, { "dc", SDC, SNDC }, { "mdc", SMDC, SNMDC }, { "scc", SSCC, SNSCC }, { "pty", SPTY, SNPTY }, { "lat", SLAT, SNLAT }, { "" }};int inof;int txtf;int prcf;int ttyf;int vecf;int ttylock;int smp_title;int usrf;long ubase;int filf;int swpf;int totflg;char partab[1];struct cdevsw cdevsw[1];struct bdevsw bdevsw[1];int allflg;int kflg;struct pte *Usrptma;struct pte *usrpt;struct pte *Sysmap = 0;int sizeSysmap;main(argc, argv)char **argv;{ register char *argp; register int allflags; if (argc == 1) { usage(); exit(1); } argc--, argv++; while (argc > 0 && **argv == '-') { argp = *argv++; argp++; argc--; while (*argp++) switch (argp[-1]) { case 'T': totflg++; break; case 'a': allflg++; break; case 'i': inof++; break; case 'k': kflg++; fcore = fmem = "/vmcore"; break; case 'x': txtf++; break; case 'p': prcf++; break; case 't': ttyf++; break; case 'u': if (argc == 0) break; argc--; usrf++; sscanf( *argv++, "%x", &ubase); break;#ifdef vax case 'v': vecf++; break;#endif /* vax */ case 'f': filf++; break; case 's': swpf++; break; case 'l': /* * SMP lock stats. Intended for proto pool only due to * the fact that SMP_STAT will not be defined in * production versions. */ switch (argp[0]) { /* * tty stats */ case 't': ttylock++; break; default: printf("usage: pstat -l[t]\n"); exit(1); } argp++; break; default: usage(); exit(1); } } if (argc>1) fcore = fmem = argv[1]; if ((fc = open(fcore, 0)) < 0) { printf("Can't find %s\n", fcore); exit(1); } if ((fm = open(fmem, 0)) < 0) { printf("Can't find %s\n", fmem); exit(1); } if (argc>0) fnlist = argv[0]; nlist(fnlist, nl); usrpt = (struct pte *)nl[USRPT].n_value; Usrptma = (struct pte *)nl[USRPTMA].n_value; if (nl[0].n_type == 0) { printf("no namelist\n"); exit(1); } allflags = filf | totflg | inof | prcf | vecf | txtf | ttyf | usrf | swpf | ttylock; if (allflags == 0) {#ifdef vax printf("pstat: one or more of -[aixpvtfsu] is required\n");#else printf("pstat: one or more of -[aixptfsu] is required\n");#endif /* vax */ exit(1); } if (filf||totflg) dofile(); if (inof||totflg) dognode(); if (prcf||totflg) doproc();#ifdef vax if (vecf||totflg) dovec();#endif /* vax */ if (txtf||totflg) dotext(); if (ttyf) dotty(); if (usrf) dousr(); if (swpf||totflg) doswap(); if (ttylock) dotty(); exit(0);}usage(){ printf("usage: pstat -[akixptfs] [-u [ubase]] [system] [core]\n");}dognode(){ register struct gnode *gp; struct gnode *xgnode; register struct gnode *agnode; register int ngn; register int ngnode; ngn = 0; ngnode = getw(nl[SNGNODE].n_value); if((xgnode = (struct gnode *)calloc(ngnode, sizeof (struct gnode))) == (struct gnode *) NULL) { perror("calloc: dognode"); exit(1); } klseek(fc, (int)(agnode = (struct gnode *)getw(nl[SGNODE].n_value)), 0); read(fc, xgnode, ngnode * sizeof(struct gnode)); for (gp = xgnode; gp < &xgnode[ngnode]; gp++) if (gp->g_count) ngn++; if (totflg) { printf("%4d/%4d\tgnodes\n", ngn, ngnode); return; } printf("%d/%d active gnodes\n", ngn, ngnode);printf(" LOC FLAGS CNT DEVICE RDC WRC GNO MODE NLK UID SIZE/DEV\n"); for (gp = xgnode; gp < &xgnode[ngnode]; gp++) { if (gp->g_count == 0) continue; printf("%8.1x ", agnode + (gp - xgnode)); putf(gp->g_lk.l_lock, 'L'); putf(gp->g_flag&GUPD, 'U'); putf(gp->g_flag&GACC, 'A'); putf(gp->g_flag&GMOUNT, 'M'); putf(gp->g_flag&GWANT, 'W'); putf(gp->g_flag>EXT, 'T'); putf(gp->g_flag&GINUSE, 'I'); putf(gp->g_flag&GCHG, 'C'); putf(gp->g_flag&GSHLOCK, 'S'); putf(gp->g_flag&GEXLOCK, 'E');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?