Annotation of coherent/b/bin/ps/ps_b4_krnl68/readker.c, revision 1.1.1.1

1.1       root        1: #include <sys/param.h>
                      2: #include <sys/proc.h>
                      3: #include <sys/sched.h>
                      4: #include <sys/dir.h>
                      5: #include <sys/seg.h>
                      6: #include <sys/stat.h>
                      7: #include <sys/uproc.h>
                      8: #include <sys/signal.h>
                      9: #include <stdio.h>
                     10: #include <ctype.h>
                     11: #include <a.out.h>
                     12: #include <pwd.h>
                     13: 
                     14: /*
                     15:  * This is a kludge for the i8086 only and will be
                     16:  * made to disappear when the segmentation (jproto)
                     17:  * is thrown away.
                     18:  */
                     19: #undef SISTACK
                     20: #define        SISTACK SIPDATA
                     21: 
                     22: /*
                     23:  * Maximum sizes.
                     24:  */
                     25: #define ARGSIZE        512
                     26: 
                     27: /*
                     28:  * For easy referencing.
                     29:  */
                     30: #define NUM_SYMS       5       /* Number of symbols to look up.  */
                     31: #define        aprocq          nl[0].n_value
                     32: #define        autimer         nl[1].n_value
                     33: #define astimer                nl[2].n_value
                     34: #define        aend            nl[4].n_value
                     35: 
                     36: /*
                     37:  * Variables.
                     38:  */
                     39: int    aflag;                          /* All processes */
                     40: int    dflag;                          /* Driver flag */
                     41: int    dbflag;                         /* Debug flag */
                     42: int    fflag;                          /* Print out all fields */
                     43: int    gflag;                          /* Print out process groups */
                     44: int    lflag;                          /* Long format */
                     45: int    mflag;                          /* Print scheduling values */
                     46: int    nflag;                          /* No header */
                     47: int    rflag;                          /* Print out real sizes */
                     48: int    tflag;                          /* Print times */
                     49: int    wflag;                          /* Wide format */
                     50: int    xflag;                          /* Get special processes */
                     51: dev_t  ttdev;                          /* Terminal device */
                     52: 
                     53: /*
                     54:  * Table for namelist.
                     55:  */
                     56: SYMENT nl[NUM_SYMS];
                     57: 
                     58: /*
                     59:  * Symbols.
                     60:  */
                     61: char    *allp;                         /* Pointer to alloc space */
                     62: char    *nfile;                        /* Namelist file */
                     63: char    *mfile;                        /* Memory file */
                     64: char    *dfile;                        /* Swap file */
                     65: char    argp[ARGSIZE];                 /* Arguments */
                     66: int     kfd;                           /* Kernel memory file descriptor */
                     67: int     mfd;                           /* Memory file descriptor */
                     68: int     dfd;                           /* Swap file descriptor */
                     69: struct  uproc u;                       /* User process area */
                     70: unsigned cutimer;                      /* Unsigned time */
                     71: PROC    cprocq;                        /* Process queue header */
                     72: PROC   w;
                     73: 
                     74: unsigned casize;                       /* Size of alloc area */
                     75: 
                     76: char *malloc();
                     77: char *uname();
                     78: 
                     79: main(argc, argv)
                     80: int argc;
                     81: char *argv[];
                     82: {
                     83:        initialise();
                     84:        execute();
                     85:        exit(0);
                     86: }
                     87: 
                     88: /*
                     89:  * Initialise.
                     90:  */
                     91: initialise()
                     92: {
                     93:        register char *cp;
                     94: 
                     95:        /* Initialise the request for coffnlist().  */
                     96:        /* The values are a STUB, taken from the kernel at386.11.  */
                     97:        strcpy(nl[0]._n._n_name, "procq");
                     98:        nl[0].n_type = 0;
                     99:        nl[0].n_value = 0xFFC170A0;
                    100:        strcpy(nl[1]._n._n_name, "utimer");
                    101:        nl[1].n_type = 0;
                    102:        nl[1].n_value = 0xFFC17FB8;
                    103:        strcpy(nl[2]._n._n_name, "stimer");
                    104:        nl[2].n_type = 0;
                    105:        nl[2].n_value = 0xFFC183C4;
                    106:        strcpy(nl[3]._n._n_name, "asize");
                    107:        nl[3].n_type = 0;
                    108:        nl[3].n_value = 0xFFC1858C;
                    109:        strcpy(nl[4]._n._n_name, "end");
                    110:        nl[4].n_type = 0;
                    111:        nl[4].n_value = 0xFFC1866C;
                    112: }
                    113: 
                    114: /*
                    115:  * Print out usage.
                    116:  */
                    117: usage()
                    118: {
                    119:        panic("Usage: ps [-][acdfgklmnrtwx]");
                    120: }
                    121: 
                    122: /*
                    123:  * Print out information about processes.
                    124:  */
                    125: execute()
                    126: {
                    127:        int c, l;
                    128: 
                    129:        if ((kfd = open("/dev/kmem", 0)) < 0)
                    130:                panic("Cannot open /dev/kmem");
                    131: 
                    132:        kread((long)autimer, &cutimer, sizeof (cprocq));
                    133:        fprintf(stderr, "DEBUG: cutimer: %d\n", cutimer);
                    134:        sleep(1);
                    135:        kread((long)autimer, &cutimer, sizeof (cprocq));
                    136:        fprintf(stderr, "DEBUG: cutimer: %d\n", cutimer);
                    137: 
                    138:        kread((long)aprocq, &cprocq, sizeof (cprocq));
                    139:        fprintf(stderr, "DEBUG: cprocq.p_pid: %d\n", cprocq.p_pid);
                    140:        fprintf(stderr, "DEBUG: cprocq.p_nforw: %x\n", cprocq.p_nforw);
                    141:        fprintf(stderr, "DEBUG: cprocq.p_nback: %x\n", cprocq.p_nback);
                    142: 
                    143:        kread((long)cprocq.p_nforw, &w, sizeof (w));
                    144:        while (w.p_nforw != cprocq.p_nforw) {
                    145:                printf("DEBUG: w.p_pid: %d\n", w.p_pid);
                    146:                printf("DEBUG: w.p_nforw: %x\n", w.p_nforw);
                    147:                printf("DEBUG: w.p_nback: %x\n", w.p_nback);
                    148:                kread((long)w.p_nforw, &w, sizeof (w));
                    149:        }
                    150: }
                    151: /*
                    152:  * Read `n' bytes into the buffer `bp' from kernel memory
                    153:  * starting at seek position `s'.
                    154:  */
                    155: kread(s, bp, n)
                    156: long s;
                    157: {
                    158:        lseek(kfd, (long)s, 0);
                    159:        if (read(kfd, bp, n) != n)
                    160:                panic("Kernel memory read error");
                    161: }
                    162: 
                    163: /*
                    164:  * Print out an error message and exit.
                    165:  */
                    166: panic(a1)
                    167: char *a1;
                    168: {
                    169:        fflush(stdout);
                    170:        fprintf(stderr, "%s", a1);
                    171:        fprintf(stderr, "\n");
                    172:        exit(1);
                    173: }

unix.superglobalmegacorp.com

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