Annotation of xinu/sys/shell/x_mem.c, revision 1.1

1.1     ! root        1: /* x_mem.c - x_mem */
        !             2: 
        !             3: #include <conf.h>
        !             4: #include <kernel.h>
        !             5: #include <proc.h>
        !             6: #include <mem.h>
        !             7: 
        !             8: /*------------------------------------------------------------------------
        !             9:  *  x_mem  -  (command mem) print memory use and free list information
        !            10:  *------------------------------------------------------------------------
        !            11:  */
        !            12: COMMAND        x_mem(stdin, stdout, stderr, nargs, args)
        !            13: int    stdin, stdout, stderr, nargs;
        !            14: char   *args[];
        !            15: {
        !            16:        int     i;
        !            17:        struct  mblock  *mptr;
        !            18:        char    str[80];
        !            19:        unsigned free;
        !            20:        unsigned avail;
        !            21:        unsigned stkmem;
        !            22: 
        !            23:        /* calculate current size of free memory and stack memory */
        !            24: 
        !            25:        for( free=0,mptr=memlist.mnext ; mptr!=(struct mblock *)NULL ;
        !            26:             mptr=mptr->mnext)
        !            27:                free += mptr->mlen;
        !            28:        for (stkmem=0,i=0 ; i<NPROC ; i++) {
        !            29:                if (proctab[i].pstate != PRFREE)
        !            30:                        stkmem += (unsigned)proctab[i].pstklen;
        !            31:        }
        !            32:        sprintf(str,
        !            33:                "Memory: %u bytes real memory, %u text, %u data, %u bss\n",
        !            34:                1 + maxaddr, (unsigned) &etext,
        !            35:                (unsigned) &edata - (unsigned) &etext,
        !            36:                (unsigned) &end - (unsigned) &edata);
        !            37:        write(stdout, str, strlen(str));
        !            38:        avail = (unsigned)maxaddr - (unsigned) &end + sizeof(int);
        !            39:        sprintf(str," initially: %7u avail\n", avail);
        !            40:        write(stdout, str, strlen(str));
        !            41:        sprintf(str," presently: %7u avail, %5u stack, %5u heap\n",
        !            42:                free, stkmem, avail - stkmem - free);
        !            43:        write(stdout, str, strlen(str));
        !            44:        sprintf(str," free list:\n");
        !            45:        write(stdout, str, strlen(str));
        !            46:        for( mptr=memlist.mnext ; mptr!=(struct mblock *)NULL ;
        !            47:             mptr=mptr->mnext) {
        !            48:                sprintf(str,"   block at %6x, length %5u (0x%x)\n",
        !            49:                        mptr, mptr->mlen, mptr->mlen);
        !            50:                write(stdout, str, strlen(str));
        !            51:        }
        !            52:        return(OK);
        !            53: }

unix.superglobalmegacorp.com

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