Annotation of xinu/sys/shell/x_ps.c, revision 1.1.1.1

1.1       root        1: /* x_ps.c - x_ps */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <proc.h>
                      6: 
                      7: LOCAL  char    hd1[] =
                      8:        "pid   name   state prio  stack range  stack length sem  message\n";
                      9: LOCAL  char    hd2[] =
                     10:        "--- -------- ----- ---- ------------- ------------ --- ---------\n";
                     11: LOCAL  char    *pstnams[] = {"curr ","free ","ready","recv ",
                     12:                            "sleep","susp ","wait ","rtim "};
                     13: LOCAL  int     psavsp;
                     14: 
                     15: /*------------------------------------------------------------------------
                     16:  *  x_ps  -  (command ps) format and print process table information
                     17:  *------------------------------------------------------------------------
                     18:  */
                     19: COMMAND        x_ps(stdin, stdout, stderr, nargs, args)
                     20: int    stdin, stdout, stderr, nargs;
                     21: char   *args[];
                     22: {
                     23:        int     i;
                     24:        char    str[80];
                     25:        struct  pentry  *pptr;
                     26:        unsigned currstk;
                     27: 
                     28:        asm("movl sp,_psavsp"); /* capture current stack pointer */
                     29:        proctab[currpid].pregs[SPINDX] = psavsp;
                     30:        write(stdout, hd1, strlen(hd1));
                     31:        write(stdout, hd2, strlen(hd2));
                     32:        for (i=0 ; i<NPROC ; i++) {
                     33:                if ((pptr = &proctab[i])->pstate == PRFREE)
                     34:                        continue;
                     35:                sprintf(str, "%3d %8s %s ", i, pptr->pname,
                     36:                        pstnams[pptr->pstate-1]);
                     37:                write(stdout, str, strlen(str));
                     38:                sprintf(str, "%4d %6x-%6x ", pptr->pprio,  pptr->plimit,
                     39:                        (unsigned)pptr->pbase + sizeof(int)-1);
                     40:                write(stdout, str, strlen(str));
                     41:                currstk = pptr->pregs[SPINDX];
                     42:                if (currstk < pptr->plimit || currstk > pptr->pbase)
                     43:                        sprintf(str, "OVERFLOWED   ");
                     44:                else
                     45:                        sprintf(str, "%4d / %4d  ", pptr->pbase - currstk,
                     46:                                pptr->pstklen);
                     47:                write(stdout, str, strlen(str));
                     48:                if (pptr->pstate == PRWAIT)
                     49:                        sprintf(str, "%3d", pptr->psem);
                     50:                else
                     51:                        sprintf(str, " - ");
                     52:                write(stdout, str, strlen(str));
                     53:                if (pptr->phasmsg)
                     54:                        sprintf(str, "%10x\n", pptr->pmsg);
                     55:                else
                     56:                        sprintf(str, "     -\n");
                     57:                write(stdout, str, strlen(str));
                     58:        }
                     59: }

unix.superglobalmegacorp.com

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