changed for new system style
authorBill Joy <wnj@ucbvax.Berkeley.EDU>
Sun, 1 Mar 1981 14:55:52 +0000 (06:55 -0800)
committerBill Joy <wnj@ucbvax.Berkeley.EDU>
Sun, 1 Mar 1981 14:55:52 +0000 (06:55 -0800)
SCCS-vsn: usr.bin/w/w.c 4.3
SCCS-vsn: bin/ps/ps.c 4.8

usr/src/bin/ps/ps.c
usr/src/usr.bin/w/w.c

index 54ab00a..8590037 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)ps.c        4.7 (Berkeley) %G%";
+static char *sccsid = "@(#)ps.c        4.8 (Berkeley) %G%";
 /*
  * ps; VAX 4BSD version
  */
 /*
  * ps; VAX 4BSD version
  */
@@ -35,6 +35,12 @@ struct nlist nl[] = {
 #define        X_CCPU          6
        { "_ecmx" },
 #define        X_ECMX          7
 #define        X_CCPU          6
        { "_ecmx" },
 #define        X_ECMX          7
+       { "_nproc" },
+#define        X_NPROC         8
+       { "_ntext" },
+#define        X_NTEXT         9
+       { "_hz" },
+#define        X_HZ            10
        { 0 },
 };
 
        { 0 },
 };
 
@@ -46,7 +52,7 @@ struct        savcom {
                int     s_ssiz;
        } sun;
        struct  asav *ap;
                int     s_ssiz;
        } sun;
        struct  asav *ap;
-} savcom[NPROC];
+} *savcom;
 
 struct asav {
        char    *a_cmdp;
 
 struct asav {
        char    *a_cmdp;
@@ -98,9 +104,11 @@ char        *gettty(), *getcmd(), *getname(), *savestr(), *alloc(), *state();
 double pcpu(), pmem();
 int    pscomp();
 int    nswap, maxslp;
 double pcpu(), pmem();
 int    pscomp();
 int    nswap, maxslp;
+struct text *atext;
 double ccpu;
 int    ecmx;
 struct pte *Usrptma, *usrpt;
 double ccpu;
 int    ecmx;
 struct pte *Usrptma, *usrpt;
+int    nproc, ntext, hz;
 
 struct ttys {
        char    name[DIRSIZ+1];
 
 struct ttys {
        char    name[DIRSIZ+1];
@@ -109,7 +117,6 @@ struct      ttys {
        struct  ttys *cand;
 } *allttys, *cand[16];
 
        struct  ttys *cand;
 } *allttys, *cand[16];
 
-struct savcom savcom[NPROC];
 int    npr;
 
 int    cmdstart;
 int    npr;
 
 int    cmdstart;
@@ -209,10 +216,13 @@ main(argc, argv)
        getdev();
        uid = getuid();
        printhdr();
        getdev();
        uid = getuid();
        printhdr();
-       procp = nl[X_PROC].n_value;
-       for (i=0; i<NPROC; i += 8) {
+       procp = getw(nl[X_PROC].n_value);
+       nproc = getw(nl[X_NPROC].n_value);
+       hz = getw(nl[X_HZ].n_value);
+       savcom = (struct savcom *)calloc(nproc, sizeof (*savcom));
+       for (i=0; i<nproc; i += 8) {
                lseek(kmem, (char *)procp, 0);
                lseek(kmem, (char *)procp, 0);
-               j = NPROC - i;
+               j = nproc - i;
                if (j > 8)
                        j = 8;
                j *= sizeof (struct proc);
                if (j > 8)
                        j = 8;
                j *= sizeof (struct proc);
@@ -268,6 +278,17 @@ main(argc, argv)
        exit(npr == 0);
 }
 
        exit(npr == 0);
 }
 
+getw(loc)
+       off_t loc;
+{
+       long word;
+
+       lseek(kmem, loc, 0);
+       if (read(kmem, &word, sizeof (word)) != sizeof (word))
+               printf("error reading kmem at %x\n", loc);
+       return (word);
+}
+
 openfiles(argc, argv)
        char **argv;
 {
 openfiles(argc, argv)
        char **argv;
 {
@@ -336,14 +357,16 @@ getkvars(argc, argv)
                exit(1);
        }
        if (uflg || vflg) {
                exit(1);
        }
        if (uflg || vflg) {
-               text = (struct text *)alloc(NTEXT * sizeof (struct text));
+               ntext = getw(nl[X_NTEXT].n_value);
+               text = (struct text *)alloc(ntext * sizeof (struct text));
                if (text == 0) {
                        fprintf(stderr, "no room for text table\n");
                        exit(1);
                }
                if (text == 0) {
                        fprintf(stderr, "no room for text table\n");
                        exit(1);
                }
-               lseek(kmem, (long)nl[X_TEXT].n_value, 0);
-               if (read(kmem, (char *)text, NTEXT * sizeof (struct text))
-                   != NTEXT * sizeof (struct text)) {
+               atext = (struct text *)getw(nl[X_TEXT].n_value);
+               lseek(kmem, (int)atext, 0);
+               if (read(kmem, (char *)text, ntext * sizeof (struct text))
+                   != ntext * sizeof (struct text)) {
                        cantread("text table", kmemf);
                        exit(1);
                }
                        cantread("text table", kmemf);
                        exit(1);
                }
@@ -579,15 +602,14 @@ save()
                if (sumcpu)
                        ap->a_cpu += u.u_cvm.vm_utime + u.u_cvm.vm_stime;
                if (mproc->p_textp && text) {
                if (sumcpu)
                        ap->a_cpu += u.u_cvm.vm_utime + u.u_cvm.vm_stime;
                if (mproc->p_textp && text) {
-                       xp = &text[mproc->p_textp -
-                                   (struct text *)nl[X_TEXT].n_value];
+                       xp = &text[mproc->p_textp - atext];
                        ap->a_tsiz = xp->x_size;
                        ap->a_txtrss = xp->x_rssize;
                        ap->a_xccount = xp->x_ccount;
                }
        }
 #undef e
                        ap->a_tsiz = xp->x_size;
                        ap->a_txtrss = xp->x_rssize;
                        ap->a_xccount = xp->x_ccount;
                }
        }
 #undef e
-       ap->a_cpu /= HZ;
+       ap->a_cpu /= hz;
        if (lflg) {
                register struct lsav *lp;
 
        if (lflg) {
                register struct lsav *lp;
 
@@ -616,10 +638,10 @@ save()
        else if (sflg) {
                if (ap->a_stat != SZOMB) {
                        for (cp = (char *)u.u_stack;
        else if (sflg) {
                if (ap->a_stat != SZOMB) {
                        for (cp = (char *)u.u_stack;
-                           cp < &user.upages[UPAGES][NBPG]; )
+                           cp < &user.upages[UPAGES][0]; )
                                if (*cp++)
                                        break;
                                if (*cp++)
                                        break;
-                       sp->sun.s_ssiz = (&user.upages[UPAGES][NBPG] - cp);
+                       sp->sun.s_ssiz = (&user.upages[UPAGES][0] - cp);
                }
        }
        npr++;
                }
        }
        npr++;
@@ -824,7 +846,7 @@ ptime(ap)
        struct asav *ap;
 {
 
        struct asav *ap;
 {
 
-       printf("%3ld:%02ld", ap->a_cpu / HZ, ap->a_cpu % HZ);
+       printf("%3ld:%02ld", ap->a_cpu / hz, ap->a_cpu % hz);
 }
 
 char   *uhdr =
 }
 
 char   *uhdr =
index b8931c9..e18cf25 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)w.c 4.2 (Berkeley) %G%";
+static char *sccsid = "@(#)w.c 4.3 (Berkeley) %G%";
 /*
  * w - print system status (who and what)
  *
 /*
  * w - print system status (who and what)
  *
@@ -23,7 +23,7 @@ static char *sccsid = "@(#)w.c        4.2 (Berkeley) %G%";
 
 #define ARGWIDTH       33      /* # chars left on 80 col crt for args */
 
 
 #define ARGWIDTH       33      /* # chars left on 80 col crt for args */
 
-struct smproc {
+struct pr {
        short   w_pid;                  /* proc.p_pid */
        char    w_flag;                 /* proc.p_flag */
        short   w_size;                 /* proc.p_size */
        short   w_pid;                  /* proc.p_pid */
        char    w_flag;                 /* proc.p_flag */
        short   w_size;                 /* proc.p_size */
@@ -35,7 +35,8 @@ struct smproc {
        dev_t   w_tty;                  /* tty device of process */
        char    w_comm[15];             /* user.u_comm, null terminated */
        char    w_args[ARGWIDTH+1];     /* args if interesting process */
        dev_t   w_tty;                  /* tty device of process */
        char    w_comm[15];             /* user.u_comm, null terminated */
        char    w_args[ARGWIDTH+1];     /* args if interesting process */
-} pr[NPROC];
+} *pr;
+int    nproc;
 
 struct nlist nl[] = {
        { "_proc" },
 
 struct nlist nl[] = {
        { "_proc" },
@@ -52,6 +53,8 @@ struct        nlist nl[] = {
 #define        X_AVENRUN       5
        { "_bootime" },
 #define        X_BOOTIME       6
 #define        X_AVENRUN       5
        { "_bootime" },
 #define        X_BOOTIME       6
+       { "_nproc" },
+#define        X_NPROC         7
        { 0 },
 };
 
        { 0 },
 };
 
@@ -66,6 +69,7 @@ dev_t tty;
 char   doing[520];             /* process attached to terminal */
 time_t proctime;               /* cpu time of process in doing */
 double avenrun[3];
 char   doing[520];             /* process attached to terminal */
 time_t proctime;               /* cpu time of process in doing */
 double avenrun[3];
+struct proc *aproc;
 
 #define        DIV60(t)        ((t+30)/60)    /* x/60 rounded */ 
 #define        TTYEQ           (tty == pr[i].w_tty)
 
 #define        DIV60(t)        ((t+30)/60)    /* x/60 rounded */ 
 #define        TTYEQ           (tty == pr[i].w_tty)
@@ -429,28 +433,20 @@ readpr()
        /*
         * Locate proc table
         */
        /*
         * Locate proc table
         */
+       lseek(kmem, (long)nl[X_NPROC].n_value, 0);
+       read(kmem, &nproc, sizeof(nproc));
+       pr = (struct pr *)calloc(nproc, sizeof (struct pr));
        np = 0;
        np = 0;
-       for (pn=0; pn<NPROC; pn++) {
-               lseek(kmem, (long)(nl[X_PROC].n_value + pn*(sizeof mproc)), 0);
+       lseek(kmem, (long)nl[X_PROC].n_value, 0);
+       read(kmem, &aproc, sizeof(aproc));
+       for (pn=0; pn<nproc; pn++) {
+               lseek(kmem, (int)(aproc + pn), 0);
                read(kmem, &mproc, sizeof mproc);
                /* decide if it's an interesting process */
                if (mproc.p_stat==0 || mproc.p_pgrp==0)
                        continue;
                if (mproc.p_flag&SDETACH)
                        continue;
                read(kmem, &mproc, sizeof mproc);
                /* decide if it's an interesting process */
                if (mproc.p_stat==0 || mproc.p_pgrp==0)
                        continue;
                if (mproc.p_flag&SDETACH)
                        continue;
-               
-#ifdef notdef
-               /*
-                * The following speeds up w on systems with lots of ttys
-                * by ignoring inits and gettys, but loses on root login shells.
-                * On Ernie it reduced user and system time by .3 seconds,
-                * an insignificant amount.  It is commented out since it
-                * will lose when root logs in.
-                */
-               if (mproc.p_uid == 0 & mproc.p_ppid == 1)
-                       continue;
-#endif
-
                /* find & read in the user structure */
                if ((mproc.p_flag & SLOAD) == 0) {
                        /* not in memory - get from swap device */
                /* find & read in the user structure */
                if ((mproc.p_flag & SLOAD) == 0) {
                        /* not in memory - get from swap device */
@@ -520,7 +516,7 @@ cont:
  */
 char *
 getargs(p)
  */
 char *
 getargs(p)
-       struct smproc *p;
+       struct pr *p;
 {
        int c, addr, nbad;
        static int abuf[512/sizeof(int)];
 {
        int c, addr, nbad;
        static int abuf[512/sizeof(int)];