changes for 4.4BSD-Lite requested by USL
[unix-history] / usr / src / bin / ps / print.c
index 6f67c03..c9173ff 100644 (file)
@@ -1,12 +1,12 @@
 /*-
 /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
  *
  * %sccs.include.redist.c%
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    8.2 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -14,28 +14,32 @@ static char sccsid[] = "@(#)print.c 5.11 (Berkeley) %G%";
 #include <sys/resource.h>
 #include <sys/proc.h>
 #include <sys/stat.h>
 #include <sys/resource.h>
 #include <sys/proc.h>
 #include <sys/stat.h>
-#include <math.h>
-#include <nlist.h>
-#include <tzfile.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <string.h>
-#include "ps.h"
 
 #ifdef SPPWAIT
 #define NEWVM
 #endif
 
 #ifdef NEWVM
 
 #ifdef SPPWAIT
 #define NEWVM
 #endif
 
 #ifdef NEWVM
-#include <vm/vm.h>
 #include <sys/ucred.h>
 #include <sys/ucred.h>
-#include <sys/kinfo_proc.h>
+#include <sys/sysctl.h>
+#include <vm/vm.h>
 #else
 #include <machine/pte.h>
 #include <sys/vmparam.h>
 #include <sys/vm.h>
 #endif
 
 #else
 #include <machine/pte.h>
 #include <sys/vmparam.h>
 #include <sys/vm.h>
 #endif
 
+#include <err.h>
+#include <math.h>
+#include <nlist.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <tzfile.h>
+
+#include "ps.h"
+
 static void printval __P((char*, struct var *));
 
 void
 static void printval __P((char*, struct var *));
 
 void
@@ -148,7 +152,7 @@ state(k, ve)
                if (flag & SSINTR)      /* interuptable (long) */
                        *cp = p->p_slptime >= MAXSLP ? 'I' : 'S';
                else
                if (flag & SSINTR)      /* interuptable (long) */
                        *cp = p->p_slptime >= MAXSLP ? 'I' : 'S';
                else
-                       *cp = (flag & SPAGE) ? 'P' : 'D';
+                       *cp = 'D';
                break;
 
        case SRUN:
                break;
 
        case SRUN:
@@ -213,7 +217,7 @@ pri(k, ve)
        VAR *v;
 
        v = ve->var;
        VAR *v;
 
        v = ve->var;
-       (void)printf("%*d", v->width, KI_PROC(k)->p_pri - PZERO);
+       (void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO);
 }
 
 void
 }
 
 void
@@ -225,11 +229,12 @@ uname(k, ve)
 
        v = ve->var;
 #ifndef NEWVM
 
        v = ve->var;
 #ifndef NEWVM
-       (void)printf("%-*s", v->width, user_from_uid(KI_PROC(k)->p_uid, 0));
-#else /* NEWVM */
-       (void)printf("%-*s", v->width,
-               user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0));
-#endif /* NEWVM */
+       (void)printf("%-*s",
+           (int)v->width, user_from_uid(KI_PROC(k)->p_uid, 0));
+#else
+       (void)printf("%-*s",
+           (int)v->width, user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0));
+#endif
 }
 
 void
 }
 
 void
@@ -241,11 +246,12 @@ runame(k, ve)
 
        v = ve->var;
 #ifndef NEWVM
 
        v = ve->var;
 #ifndef NEWVM
-       (void)printf("%-*s", v->width, user_from_uid(KI_PROC(k)->p_ruid, 0));
-#else /* NEWVM */
-       (void)printf("%-*s", v->width,
-               user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0));
-#endif /* NEWVM */
+       (void)printf("%-*s",
+           (int)v->width, user_from_uid(KI_PROC(k)->p_ruid, 0));
+#else
+       (void)printf("%-*s",
+           (int)v->width, user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0));
+#endif
 }
 
 void
 }
 
 void
@@ -299,7 +305,6 @@ longtname(k, ve)
        char *ttname;
 
        v = ve->var;
        char *ttname;
 
        v = ve->var;
-
        dev = KI_EPROC(k)->e_tdev;
        if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
                (void)printf("%-*s", v->width, "??");
        dev = KI_EPROC(k)->e_tdev;
        if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
                (void)printf("%-*s", v->width, "??");
@@ -348,7 +353,6 @@ lstarted(k, ve)
        char buf[100];
 
        v = ve->var;
        char buf[100];
 
        v = ve->var;
-
        if (!k->ki_u.u_valid) {
                (void)printf("%-*s", v->width, "-");
                return;
        if (!k->ki_u.u_valid) {
                (void)printf("%-*s", v->width, "-");
                return;
@@ -445,10 +449,13 @@ cputime(k, ve)
                secs = 0;
                psecs = 0;
        } else {
                secs = 0;
                psecs = 0;
        } else {
-               secs = KI_PROC(k)->p_utime.tv_sec +
-                       KI_PROC(k)->p_stime.tv_sec;
-               psecs = KI_PROC(k)->p_utime.tv_usec +
-                       KI_PROC(k)->p_stime.tv_usec;
+               /*
+                * This counts time spent handling interrupts.  We could
+                * fix this, but it is not 100% trivial (and interrupt
+                * time fractions only work on the sparc anyway).       XXX
+                */
+               secs = KI_PROC(k)->p_rtime.tv_sec;
+               psecs = KI_PROC(k)->p_rtime.tv_usec;
                if (sumrusage) {
                        secs += k->ki_u.u_cru.ru_utime.tv_sec +
                                k->ki_u.u_cru.ru_stime.tv_sec;
                if (sumrusage) {
                        secs += k->ki_u.u_cru.ru_utime.tv_sec +
                                k->ki_u.u_cru.ru_stime.tv_sec;
@@ -485,12 +492,12 @@ getpcpu(k)
 #define        fxtofl(fixpt)   ((double)(fixpt) / fscale)
 
        /* XXX - I don't like this */
 #define        fxtofl(fixpt)   ((double)(fixpt) / fscale)
 
        /* XXX - I don't like this */
-       if (p->p_time == 0 || (p->p_flag & SLOAD) == 0)
+       if (p->p_swtime == 0 || (p->p_flag & SLOAD) == 0)
                return (0.0);
        if (rawcpu)
                return (100.0 * fxtofl(p->p_pctcpu));
        return (100.0 * fxtofl(p->p_pctcpu) /
                return (0.0);
        if (rawcpu)
                return (100.0 * fxtofl(p->p_pctcpu));
        return (100.0 * fxtofl(p->p_pctcpu) /
-               (1.0 - exp(p->p_time * log(fxtofl(ccpu)))));
+               (1.0 - exp(p->p_swtime * log(fxtofl(ccpu)))));
 }
 
 void
 }
 
 void
@@ -697,6 +704,6 @@ printval(bp, v)
                (void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
                break;
        default:
                (void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
                break;
        default:
-               err("unknown type %d", v->type);
+               errx(1, "unknown type %d", v->type);
        }
 }
        }
 }