Annotation of researchv10no/cmd/pstat.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Print system stuff
        !             3:  */
        !             4: 
        !             5: #define mask(x) (x&0377)
        !             6: #define        clear(x) ((int)x&0x7fffffff)
        !             7: 
        !             8: #include <sys/param.h>
        !             9: #include <sys/file.h>
        !            10: #include <sys/user.h>
        !            11: #include <sys/proc.h>
        !            12: #include <sys/text.h>
        !            13: #include <sys/inode.h>
        !            14: #include <sys/conf.h>
        !            15: #include <nlist.h>
        !            16: #include <sys/vm.h>
        !            17: #include <sys/pte.h>
        !            18: #include <stdio.h>
        !            19: 
        !            20: char   *fcore  = "/dev/mem";
        !            21: char   *fnlist = "/unix";
        !            22: int    fc;
        !            23: 
        !            24: struct nlist nl[] = {
        !            25: #define        SINODE  0
        !            26:        { "_inode" },
        !            27: #define        STEXT   1
        !            28:        { "_text" },
        !            29: #define        SPROC   2
        !            30:        { "_proc" },
        !            31: #define        SFIL    3
        !            32:        { "_file" },
        !            33: #define        USRPTMA 4
        !            34:        { "_Usrptmap" },
        !            35: #define        USRPT   5
        !            36:        { "_usrpt" },
        !            37: #define        SNPROC  6
        !            38:        { "_proccnt" },
        !            39: #define        SNTEXT  7
        !            40:        { "_textcnt" },
        !            41: #define        SNFILE  8
        !            42:        { "_filecnt" },
        !            43: #define        SNINODE 9
        !            44:        { "_inodecnt" },
        !            45: #define        SNSWAPMAP 10
        !            46:        { "_swmapcnt" },
        !            47:        0,
        !            48: };
        !            49: 
        !            50: int    inof;           /* inode table */
        !            51: int    txtf;           /* text table */
        !            52: int    prcf;           /* proc table */
        !            53: int    usrf;           /* user struct */
        !            54: long   ubase;
        !            55: int    filf;           /* file table */
        !            56: int    totflg;         /* total table usage */
        !            57: char   partab[1];
        !            58: struct cdevsw  cdevsw[1];
        !            59: struct bdevsw  bdevsw[1];
        !            60: int    allflg;
        !            61: int    kflg;
        !            62: struct pte *Usrptma;
        !            63: struct pte *usrpt;
        !            64: long   seekmask = 0xffffffff;
        !            65: 
        !            66: main(argc, argv)
        !            67: char **argv;
        !            68: {
        !            69:        register char *argp;
        !            70: 
        !            71:        argc--, argv++;
        !            72:        while (argc > 0 && **argv == '-') {
        !            73:                argp = *argv++;
        !            74:                argp++;
        !            75:                argc--;
        !            76:                while (*argp++)
        !            77:                switch (argp[-1]) {
        !            78: 
        !            79:                case 'T':
        !            80:                        totflg++;
        !            81:                        break;
        !            82: 
        !            83:                case 'a':
        !            84:                        allflg++;
        !            85:                        break;
        !            86: 
        !            87:                case 'i':
        !            88:                        inof++;
        !            89:                        break;
        !            90: 
        !            91:                case 'k':
        !            92:                        kflg++;
        !            93:                        fcore = "/vmcore";
        !            94:                        seekmask = 0x7fffffff;
        !            95:                        break;
        !            96: 
        !            97:                case 'x':
        !            98:                        txtf++;
        !            99:                        break;
        !           100: 
        !           101:                case 'p':
        !           102:                        prcf++;
        !           103:                        break;
        !           104: 
        !           105:                case 'u':
        !           106:                        if (argc == 0)
        !           107:                                break;
        !           108:                        argc--;
        !           109:                        usrf++;
        !           110:                        sscanf( *argv++, "%x", &ubase);
        !           111:                        break;
        !           112: 
        !           113:                case 'f':
        !           114:                        filf++;
        !           115:                        break;
        !           116:                }
        !           117:        }
        !           118:        if (argc>0) {
        !           119:                fcore = argv[0];
        !           120:                seekmask = 0x7fffffff;
        !           121:        }
        !           122:        if ((fc = open(fcore, 0)) < 0) {
        !           123:                perror(fcore);
        !           124:                exit(1);
        !           125:        }
        !           126:        if (argc>1)
        !           127:                fnlist = argv[1];
        !           128:        nlist(fnlist, nl);
        !           129:        if (nl[0].n_type == 0) {
        !           130:                fprintf(stderr, "no namelist\n");
        !           131:                exit(1);
        !           132:        }
        !           133:        usrpt = (struct pte *)nl[USRPT].n_value;
        !           134:        Usrptma = (struct pte *)nl[USRPTMA].n_value;
        !           135:        if (filf||totflg)
        !           136:                dofile();
        !           137:        if (inof||totflg)
        !           138:                doinode();
        !           139:        if (prcf||totflg)
        !           140:                doproc();
        !           141:        if (txtf||totflg)
        !           142:                dotext();
        !           143:        if (usrf)
        !           144:                dousr();
        !           145:        exit(0);
        !           146: }
        !           147: 
        !           148: doinode()
        !           149: {
        !           150:        register struct inode *ip;
        !           151:        struct inode *xinode, *ainode;
        !           152:        register int nin;
        !           153:        int ninode;
        !           154: 
        !           155:        nin = 0;
        !           156:        ninode = getw(nl[SNINODE].n_value);
        !           157:        xinode = (struct inode *)calloc(ninode, sizeof (struct inode));
        !           158:        xxseek(fc, (int)(ainode = (struct inode *)(nl[SINODE].n_value)), 0);
        !           159:        read(fc, xinode, ninode * sizeof(struct inode));
        !           160:        for (ip = xinode; ip < &xinode[ninode]; ip++)
        !           161:                if (ip->i_count)
        !           162:                        nin++;
        !           163:        printf("%5d/%5d inodes\n", nin, ninode);
        !           164:        if (totflg)
        !           165:                return;
        !           166:        printf("   LOC    FLAGS  CNT FS  DEVICE  INO   MODE  NLN UID   SPTR   SIZE/DEV MROOT\n");
        !           167:        for (ip = xinode; ip < &xinode[ninode]; ip++) {
        !           168:                if (ip->i_count == 0)
        !           169:                        continue;
        !           170:                printf("%8.1x ", ainode + (ip - xinode));
        !           171:                putf(ip->i_flag&ILOCK, 'L');
        !           172:                putf(ip->i_flag&IUPD, 'U');
        !           173:                putf(ip->i_flag&IACC, 'A');
        !           174:                putf(ip->i_flag&IOPEN, 'O');
        !           175:                putf(ip->i_flag&IWANT, 'W');
        !           176:                putf(ip->i_flag&ITEXT, 'T');
        !           177:                printf("%4d", ip->i_count&0377);
        !           178:                printf("%3d", ip->i_fstyp);
        !           179:                printf("%4d,%3d", major(ip->i_dev), minor(ip->i_dev));
        !           180:                printf("%6d", ip->i_number);
        !           181:                printf("%7o", ip->i_mode & 0xffff);
        !           182:                printf("%4d", ip->i_nlink);
        !           183:                printf("%4d", ip->i_uid);
        !           184:                printf("%8x", (int)ip->i_sptr&0xffffff);
        !           185:                if ((ip->i_mode&IFMT)==IFBLK || (ip->i_mode&IFMT)==IFCHR)
        !           186:                        printf("%6d,%3d", major(ip->i_un.i_rdev), minor(ip->i_un.i_rdev));
        !           187:                else
        !           188:                        printf("%10ld", ip->i_size);
        !           189:                printf("%8x", (int)ip->i_mroot&0xfffffff);
        !           190:                printf("\n");
        !           191:        }
        !           192:        free(xinode);
        !           193: }
        !           194: 
        !           195: getw(loc)
        !           196:        off_t loc;
        !           197: {
        !           198:        int word;
        !           199: 
        !           200:        if (kflg)
        !           201:                loc &= 0x7fffffff;
        !           202:        xxseek(fc, loc, 0);
        !           203:        read(fc, &word, sizeof (word));
        !           204:        if (kflg)
        !           205:                word &= 0x7fffffff;
        !           206:        return (word);
        !           207: }
        !           208: 
        !           209: putf(v, n)
        !           210: {
        !           211:        if (v)
        !           212:                printf("%c", n);
        !           213:        else
        !           214:                printf(" ");
        !           215: }
        !           216: 
        !           217: dotext()
        !           218: {
        !           219:        register struct text *xp;
        !           220:        int ntext;
        !           221:        struct text *xtext, *atext;
        !           222:        int ntx;
        !           223: 
        !           224:        ntx = 0;
        !           225:        ntext = getw(nl[SNTEXT].n_value);
        !           226:        xtext = (struct text *)calloc(ntext, sizeof (struct text));
        !           227:        xxseek(fc, (int)(atext = (struct text *)(nl[STEXT].n_value)), 0);
        !           228:        read(fc, xtext, ntext * sizeof (struct text));
        !           229:        for (xp = xtext; xp < &xtext[ntext]; xp++)
        !           230:                if (xp->x_iptr!=NULL)
        !           231:                        ntx++;
        !           232:        printf("%5d/%5d active texts\n", ntx, ntext);
        !           233:        if (totflg)
        !           234:                return;
        !           235:        printf("   LOC   FLAGS DADDR      CADDR  RSS SIZE      IPTR  CNT CCNT\n");
        !           236:        for (xp = xtext; xp < &xtext[ntext]; xp++) {
        !           237:                if (xp->x_iptr == NULL)
        !           238:                        continue;
        !           239:                printf("%8.1x", atext + (xp - xtext));
        !           240:                printf(" ");
        !           241:                putf(xp->x_flag&XPAGI, 'P');
        !           242:                putf(xp->x_flag&XTRC, 'T');
        !           243:                putf(xp->x_flag&XWRIT, 'W');
        !           244:                putf(xp->x_flag&XLOAD, 'L');
        !           245:                putf(xp->x_flag&XLOCK, 'K');
        !           246:                putf(xp->x_flag&XWANT, 'w');
        !           247:                printf("%5x", xp->x_daddr[0]);
        !           248:                printf("%11x", xp->x_caddr);
        !           249:                printf("%5d", xp->x_rssize);
        !           250:                printf("%5d", xp->x_size);
        !           251:                printf("%10.1x", xp->x_iptr);
        !           252:                printf("%5d", xp->x_count&0377);
        !           253:                printf("%5d", xp->x_ccount);
        !           254:                printf("\n");
        !           255:        }
        !           256:        free(xtext);
        !           257: }
        !           258: 
        !           259: doproc()
        !           260: {
        !           261:        struct proc *xproc, *aproc;
        !           262:        int nproc;
        !           263:        register struct proc *pp;
        !           264:        register np;
        !           265: 
        !           266:        nproc = getw(nl[SNPROC].n_value);
        !           267:        xproc = (struct proc *)calloc(nproc, sizeof (struct proc));
        !           268:        xxseek(fc, (int)(aproc = (struct proc *)(nl[SPROC].n_value)), 0);
        !           269:        read(fc, xproc, nproc * sizeof (struct proc));
        !           270:        np = 0;
        !           271:        for (pp=xproc; pp < &xproc[nproc]; pp++)
        !           272:                if (pp->p_stat)
        !           273:                        np++;
        !           274:        printf("%5d/%5d processes\n", np, nproc);
        !           275:        if (totflg)
        !           276:                return;
        !           277:        printf("   LOC    S    F     ADDR PRI  SIG  UID SLP TIM  CPU  NI   PGRP    PID   PPID  RSS SRSS SIZE    WCHAN    LINK   TEXTP CLKT\n");
        !           278:        for (pp=xproc; pp<&xproc[nproc]; pp++) {
        !           279:                if (pp->p_stat==0 && allflg==0)
        !           280:                        continue;
        !           281:                printf("%8x", aproc + (pp - xproc));
        !           282:                printf(" %2d", pp->p_stat);
        !           283:                printf(" %4x", pp->p_flag & 0xffff);
        !           284:                printf(" %8x", pp->p_addr);
        !           285:                printf(" %3d", pp->p_pri);
        !           286:                printf(" %4x", pp->p_sig);
        !           287:                printf(" %4d", pp->p_uid);
        !           288:                printf(" %3d", pp->p_slptime);
        !           289:                printf(" %3d", pp->p_time);
        !           290:                printf(" %4d", pp->p_cpu&0377);
        !           291:                printf(" %3d", pp->p_nice);
        !           292:                printf(" %6d", pp->p_pgrp);
        !           293:                printf(" %6d", pp->p_pid);
        !           294:                printf(" %6d", pp->p_ppid);
        !           295:                printf(" %4x", pp->p_rssize);
        !           296:                printf(" %4x", pp->p_swrss);
        !           297:                printf(" %5x", pp->p_dsize+pp->p_ssize);
        !           298:                printf(" %7x", clear(pp->p_wchan));
        !           299:                printf(" %7x", clear(pp->p_link));
        !           300:                printf(" %7x", clear(pp->p_textp));
        !           301:                printf("    %u", pp->p_clktim);
        !           302:                printf("\n");
        !           303:        }
        !           304: }
        !           305: 
        !           306: dousr()
        !           307: {
        !           308:        struct user U;
        !           309:        register i, *ip;
        !           310: 
        !           311:        /* This wins only if PAGSIZ > sizeof (struct user) */
        !           312:        xxseek(fc, ubase * NBPG, 0);
        !           313:        read(fc, &U, sizeof(U));
        !           314:        printf("pcb");
        !           315:        ip = (int *)&U.u_pcb;
        !           316:        while (ip < &U.u_arg[0]) {
        !           317:                if ((ip - (int *)&U.u_pcb) % 4 == 0)
        !           318:                        printf("\t");
        !           319:                printf("%x ", *ip++);
        !           320:                if ((ip - (int *)&U.u_pcb) % 4 == 0)
        !           321:                        printf("\n");
        !           322:        }
        !           323:        if ((ip - (int *)&U.u_pcb) % 4 != 0)
        !           324:                printf("\n");
        !           325:        printf("arg\t");
        !           326:        for (i=0; i<5; i++)
        !           327:                printf(" %.1x", U.u_arg[i]);
        !           328:        printf("\n");
        !           329:        for (i=0; i<sizeof(label_t)/sizeof(int); i++) {
        !           330:                if (i%5==0)
        !           331:                        printf("\t");
        !           332:                printf("%9.1x", U.u_ssav[i]);
        !           333:                if (i%5==4)
        !           334:                        printf("\n");
        !           335:        }
        !           336:        if (i%5)
        !           337:                printf("\n");
        !           338:        printf("segflg\t%d\nerror %d\n", U.u_segflg, U.u_error);
        !           339:        printf("uids\t%d,%d,%d,%d\n", U.u_uid,U.u_gid,U.u_ruid,U.u_rgid);
        !           340:        printf("procp\t%.1x\n", U.u_procp);
        !           341:        printf("ap\t%.1x\n", U.u_ap);
        !           342:        printf("r_val?\t%.1x %.1x\n", U.u_r.r_val1, U.u_r.r_val2);
        !           343:        printf("base, count, offset %.1x %.1x %ld\n", U.u_base,
        !           344:                U.u_count, U.u_offset);
        !           345:        printf("cdir rdir %.1x %.1x\n", U.u_cdir, U.u_rdir);
        !           346:        printf("file\t");
        !           347:        for (i=0; i<10; i++)
        !           348:                printf("%9.1x", U.u_ofile[i]);
        !           349:        printf("\n\t");
        !           350:        for (i=10; i<NOFILE; i++)
        !           351:                printf("%9.1x", U.u_ofile[i]);
        !           352:        printf("\n");
        !           353:        printf("pofile\t");
        !           354:        for (i=0; i<10; i++)
        !           355:                printf("%9.1x", U.u_pofile[i]);
        !           356:        printf("\n\t");
        !           357:        for (i=10; i<NOFILE; i++)
        !           358:                printf("%9.1x", U.u_pofile[i]);
        !           359:        printf("\n");
        !           360:        printf("ssav");
        !           361:        for (i=0; i<sizeof(label_t)/sizeof(int); i++) {
        !           362:                if (i%5==0)
        !           363:                        printf("\t");
        !           364:                printf("%9.1x", U.u_ssav[i]);
        !           365:                if (i%5==4)
        !           366:                        printf("\n");
        !           367:        }
        !           368:        if (i%5)
        !           369:                printf("\n");
        !           370:        printf("sigs\t");
        !           371:        for (i=0; i<NSIG; i++)
        !           372:                printf("%.1x ", U.u_signal[i]);
        !           373:        printf("\n");
        !           374:        printf("ar0\t%.1x\n", U.u_ar0);
        !           375:        printf("prof\t%X %X %X %X\n", U.u_prof.pr_base, U.u_prof.pr_size,
        !           376:            U.u_prof.pr_off, U.u_prof.pr_scale);
        !           377:        /*
        !           378:        printf("ttyp\t%.1x\n", U.u_ttyp);
        !           379:        printf("ttyd\t%d,%d\n", major(U.u_ttyd), minor(U.u_ttyd));
        !           380:        */
        !           381:        printf("exdata\t");
        !           382:        ip = (int *)&U.u_exdata;
        !           383:        for (i = 0; i < 8; i++)
        !           384:                printf("%.1D ", *ip++);
        !           385:        printf("\n");
        !           386:        printf("comm %.14s\n", U.u_comm);
        !           387:        printf("start\t%D\n", U.u_start);
        !           388:        printf("acflag\t%D\n", U.u_acflag);
        !           389:        printf("cmask\t%D\n", U.u_cmask);
        !           390:        printf("sizes\t%.1x %.1x %.1x\n", U.u_tsize, U.u_dsize, U.u_ssize);
        !           391:        printf("vm\t");
        !           392:        ip = (int *)&U.u_vm;
        !           393:        for (i = 0; i < sizeof(U.u_vm)/sizeof(int); i++)
        !           394:                printf("%D ", ip[i]);
        !           395:        printf("\n");
        !           396:        ip = (int *)&U.u_cvm;
        !           397:        printf("cvm\t");
        !           398:        for (i = 0; i < sizeof(U.u_vm)/sizeof(int); i++)
        !           399:                printf("%D ", ip[i]);
        !           400:        printf("\n");
        !           401: /*
        !           402:        i =  U.u_stack - &U;
        !           403:        while (U[++i] == 0);
        !           404:        i &= ~07;
        !           405:        while (i < 512) {
        !           406:                printf("%x ", 0140000+2*i);
        !           407:                for (j=0; j<8; j++)
        !           408:                        printf("%9x", U[i++]);
        !           409:                printf("\n");
        !           410:        }
        !           411: */
        !           412: }
        !           413: 
        !           414: oatoi(s)
        !           415: char *s;
        !           416: {
        !           417:        register v;
        !           418: 
        !           419:        v = 0;
        !           420:        while (*s)
        !           421:                v = (v<<3) + *s++ - '0';
        !           422:        return(v);
        !           423: }
        !           424: 
        !           425: dofile()
        !           426: {
        !           427:        int nfile;
        !           428:        struct file *xfile, *afile;
        !           429:        register struct file *fp;
        !           430:        register nf;
        !           431: 
        !           432:        nf = 0;
        !           433:        nfile = getw(nl[SNFILE].n_value);
        !           434:        xfile = (struct file *)calloc(nfile, sizeof (struct file));
        !           435:        xxseek(fc, (int)(afile = (struct file *)(nl[SFIL].n_value)), 0);
        !           436:        read(fc, xfile, nfile * sizeof (struct file));
        !           437:        for (fp=xfile; fp < &xfile[nfile]; fp++)
        !           438:                if (fp->f_count)
        !           439:                        nf++;
        !           440:        printf("%5d/%5d open files\n", nf, nfile);
        !           441:        if (totflg)
        !           442:                return;
        !           443:        printf("   LOC   FLG  CNT   INO    OFFS\n");
        !           444:        for (fp=xfile; fp < &xfile[nfile]; fp++,afile++) {
        !           445:                if (fp->f_count==0)
        !           446:                        continue;
        !           447:                printf("%8x ", afile);
        !           448:                putf(fp->f_flag&FREAD, 'R');
        !           449:                putf(fp->f_flag&FWRITE, 'W');
        !           450:                putf(fp->f_flag&FHUNGUP, 'H');
        !           451:                printf("%4d", mask(fp->f_count));
        !           452:                printf("%9.1x", fp->f_inode);
        !           453:                printf("  %ld\n", fp->f_offset);
        !           454:        }
        !           455: }
        !           456: 
        !           457: xxseek(f, l, w)
        !           458: long l;
        !           459: {
        !           460:        return(lseek(f, l&seekmask, w));
        !           461: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.