diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-01-08 18:18:36 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-01-08 18:18:36 +0000 |
commit | ec885d2f7f9a4cf6128f8c91551ca2b08c699eac (patch) | |
tree | 59551b84af070d9b3d26a8a5f61e8481fdcc91b9 /bin | |
parent | a1c4883332d6e8759b8aaae5b00364bca088e604 (diff) |
Convert to kinfo_proc2. The sort order for -u and -m will be different
due to a bug fix in the sort routine.
Diffstat (limited to 'bin')
-rw-r--r-- | bin/ps/extern.h | 68 | ||||
-rw-r--r-- | bin/ps/fmt.c | 4 | ||||
-rw-r--r-- | bin/ps/keyword.c | 92 | ||||
-rw-r--r-- | bin/ps/print.c | 304 | ||||
-rw-r--r-- | bin/ps/ps.c | 135 | ||||
-rw-r--r-- | bin/ps/ps.h | 16 |
6 files changed, 255 insertions, 364 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h index e906cf41662..df48dd51841 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.9 2003/06/02 23:32:09 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.10 2004/01/08 18:18:35 millert Exp $ */ /* $NetBSD: extern.h,v 1.10 1995/05/21 13:38:27 mycroft Exp $ */ /*- @@ -32,7 +32,6 @@ * @(#)extern.h 8.3 (Berkeley) 4/2/94 */ -struct kinfo; struct nlist; struct var; struct varent; @@ -44,44 +43,41 @@ extern VAR var[]; extern VARENT *vhead; __BEGIN_DECLS -void command(KINFO *, VARENT *); -void cputime(KINFO *, VARENT *); +void command(const struct kinfo_proc2 *, VARENT *); +void cputime(const struct kinfo_proc2 *, VARENT *); int donlist(void); -void evar(KINFO *, VARENT *); -void emulname(KINFO *, VARENT *); -void fmt_puts(char *, int *); +void emulname(const struct kinfo_proc2 *, VARENT *); +void fmt_puts(const char *, int *); void fmt_putc(int, int *); -double getpcpu(KINFO *); -double getpmem(KINFO *); -void gname(KINFO *, VARENT *); -void logname(KINFO *, VARENT *); -void longtname(KINFO *, VARENT *); -void lstarted(KINFO *, VARENT *); -void maxrss(KINFO *, VARENT *); +double getpcpu(const struct kinfo_proc2 *); +double getpmem(const struct kinfo_proc2 *); +void gname(const struct kinfo_proc2 *, VARENT *); +void logname(const struct kinfo_proc2 *, VARENT *); +void longtname(const struct kinfo_proc2 *, VARENT *); +void lstarted(const struct kinfo_proc2 *, VARENT *); +void maxrss(const struct kinfo_proc2 *, VARENT *); void nlisterr(struct nlist *); -void p_rssize(KINFO *, VARENT *); -void pagein(KINFO *, VARENT *); +void p_rssize(const struct kinfo_proc2 *, VARENT *); +void pagein(const struct kinfo_proc2 *, VARENT *); void parsefmt(char *); -void pcpu(KINFO *, VARENT *); -void pmem(KINFO *, VARENT *); -void pri(KINFO *, VARENT *); +void pcpu(const struct kinfo_proc2 *, VARENT *); +void pmem(const struct kinfo_proc2 *, VARENT *); +void pri(const struct kinfo_proc2 *, VARENT *); void printheader(void); -void pvar(KINFO *, VARENT *); -void rgname(KINFO *, VARENT *); -void rssize(KINFO *, VARENT *); -void runame(KINFO *, VARENT *); -void rvar(KINFO *, VARENT *); +void pvar(const struct kinfo_proc2 *kp, VARENT *); +void rgname(const struct kinfo_proc2 *, VARENT *); +void rssize(const struct kinfo_proc2 *, VARENT *); +void runame(const struct kinfo_proc2 *, VARENT *); void showkey(void); -void started(KINFO *, VARENT *); -void state(KINFO *, VARENT *); -void tdev(KINFO *, VARENT *); -void tname(KINFO *, VARENT *); -void tsize(KINFO *, VARENT *); -void dsize(KINFO *, VARENT *); -void ssize(KINFO *, VARENT *); -void ucomm(KINFO *, VARENT *); -void uname(KINFO *, VARENT *); -void uvar(KINFO *, VARENT *); -void vsize(KINFO *, VARENT *); -void wchan(KINFO *, VARENT *); +void started(const struct kinfo_proc2 *, VARENT *); +void state(const struct kinfo_proc2 *, VARENT *); +void tdev(const struct kinfo_proc2 *, VARENT *); +void tname(const struct kinfo_proc2 *, VARENT *); +void tsize(const struct kinfo_proc2 *, VARENT *); +void dsize(const struct kinfo_proc2 *, VARENT *); +void ssize(const struct kinfo_proc2 *, VARENT *); +void ucomm(const struct kinfo_proc2 *, VARENT *); +void uname(const struct kinfo_proc2 *, VARENT *); +void vsize(const struct kinfo_proc2 *, VARENT *); +void wchan(const struct kinfo_proc2 *, VARENT *); __END_DECLS diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c index f49f3be1bc0..8e193746535 100644 --- a/bin/ps/fmt.c +++ b/bin/ps/fmt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fmt.c,v 1.6 2003/09/26 00:48:44 deraadt Exp $ */ +/* $OpenBSD: fmt.c,v 1.7 2004/01/08 18:18:35 millert Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -47,7 +47,7 @@ #include "extern.h" void -fmt_puts(char *s, int *leftp) +fmt_puts(const char *s, int *leftp) { static char *v = NULL, *nv; static int maxlen = 0; diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index abc26a608d1..456b3c5614c 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyword.c,v 1.20 2003/12/16 00:37:21 deraadt Exp $ */ +/* $OpenBSD: keyword.c,v 1.21 2004/01/08 18:18:35 millert Exp $ */ /* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: keyword.c,v 1.20 2003/12/16 00:37:21 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: keyword.c,v 1.21 2004/01/08 18:18:35 millert Exp $"; #endif #endif /* not lint */ @@ -68,10 +68,7 @@ int utime(), stime(), ixrss(), idrss(), isrss(); #endif /* Compute offset in common structures. */ -#define POFF(x) offsetof(struct proc, x) -#define EOFF(x) offsetof(struct eproc, x) -#define UOFF(x) offsetof(struct usave, x) -#define ROFF(x) offsetof(struct rusage, x) +#define POFF(x) offsetof(struct kinfo_proc2, x) #define UIDFMT "u" #define UIDLEN 5 @@ -86,103 +83,104 @@ int utime(), stime(), ixrss(), idrss(), isrss(); #define USERLEN 8 +/* Bit types must match their respective entries in struct kinfo_proc2 */ VAR var[] = { {"%cpu", "%CPU", NULL, 0, pcpu, 4}, {"%mem", "%MEM", NULL, 0, pmem, 4}, - {"acflag", "ACFLG", NULL, 0, pvar, 3, 0, POFF(p_acflag), USHORT, "x"}, + {"acflag", "ACFLG", NULL, 0, pvar, 3, 0, POFF(p_acflag), UINT16, "x"}, {"acflg", "", "acflag"}, {"args", "", "command"}, {"blocked", "", "sigmask"}, {"caught", "", "sigcatch"}, {"comm", "", "ucomm"}, {"command", "COMMAND", NULL, COMM|LJUST|USER, command, 16}, - {"cpu", "CPU", NULL, 0, pvar, 3, 0, POFF(p_estcpu), UINT, "d"}, + {"cpu", "CPU", NULL, 0, pvar, 3, 0, POFF(p_estcpu), UINT32, "d"}, {"cputime", "", "time"}, {"dsiz", "DSIZ", NULL, 0, dsize, 4}, {"emul", "EMUL", NULL, LJUST, emulname, EMULNAMELEN}, {"etime", "", "start"}, - {"f", "F", NULL, 0, pvar, 7, 0, POFF(p_flag), INT, "x"}, + {"f", "F", NULL, 0, pvar, 7, 0, POFF(p_flag), INT32, "x"}, {"flags", "", "f"}, - GID("gid", "GID", evar, EOFF(e_ucred.cr_gid)), + GID("gid", "GID", pvar, POFF(p_gid)), {"group", "GROUP", NULL, LJUST, gname, USERLEN}, - {"holdcnt", "HOLDCNT", NULL, 0, pvar, 8, 0, POFF(p_holdcnt), INT, "d"}, + {"holdcnt", "HOLDCNT", NULL, 0, pvar, 8, 0, POFF(p_holdcnt), INT32, "d"}, {"ignored", "", "sigignore"}, - {"inblk", "INBLK", NULL, USER, rvar, 4, 0, ROFF(ru_inblock), LONG, "d"}, + {"inblk", "INBLK", NULL, USER, pvar, 4, 0, POFF(p_uru_inblock), UINT64, "lld"}, {"inblock", "", "inblk"}, - {"jobc", "JOBC", NULL, 0, evar, 4, 0, EOFF(e_jobc), SHORT, "d"}, - {"ktrace", "KTRACE", NULL, 0, pvar, 8, 0, POFF(p_traceflag), INT, "x"}, + {"jobc", "JOBC", NULL, 0, pvar, 4, 0, POFF(p_jobc), INT16, "d"}, + {"ktrace", "KTRACE", NULL, 0, pvar, 8, 0, POFF(p_traceflag), INT32, "x"}, /* XXX */ - {"ktracep", "KTRACEP", NULL, 0, pvar, 8, 0, POFF(p_tracep), KPTR, "x"}, + {"ktracep", "KTRACEP", NULL, 0, pvar, 8, 0, POFF(p_tracep), UINT64, "llx"}, {"lim", "LIM", NULL, 0, maxrss, 5}, {"login", "LOGIN", NULL, LJUST, logname, MAXLOGNAME}, {"logname", "", "login"}, {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 28}, - {"majflt", "MAJFLT", NULL, USER, rvar, 4, 0, ROFF(ru_majflt), LONG, "d"}, - {"minflt", "MINFLT", NULL, USER, rvar, 4, 0, ROFF(ru_minflt), LONG, "d"}, - {"msgrcv", "MSGRCV", NULL, USER, rvar, 4, 0, ROFF(ru_msgrcv), LONG, "d"}, - {"msgsnd", "MSGSND", NULL, USER, rvar, 4, 0, ROFF(ru_msgsnd), LONG, "d"}, + {"majflt", "MAJFLT", NULL, USER, pvar, 4, 0, POFF(p_uru_majflt), UINT64, "lld"}, + {"minflt", "MINFLT", NULL, USER, pvar, 4, 0, POFF(p_uru_minflt), UINT64, "lld"}, + {"msgrcv", "MSGRCV", NULL, USER, pvar, 4, 0, POFF(p_uru_msgrcv), UINT64, "lld"}, + {"msgsnd", "MSGSND", NULL, USER, pvar, 4, 0, POFF(p_uru_msgsnd), UINT64, "lld"}, {"ni", "", "nice"}, - {"nice", "NI", NULL, 0, pvar, 2, 0, POFF(p_nice), CHAR, "d"}, - {"nivcsw", "NIVCSW", NULL, USER, rvar, 5, 0, ROFF(ru_nivcsw), LONG, "d"}, + {"nice", "NI", NULL, 0, pvar, 2, 0, POFF(p_nice), UINT8, "d"}, + {"nivcsw", "NIVCSW", NULL, USER, pvar, 5, 0, POFF(p_uru_nivcsw), UINT64, "lld"}, {"nsignals", "", "nsigs"}, - {"nsigs", "NSIGS", NULL, USER, rvar, 4, 0, ROFF(ru_nsignals), LONG, "d"}, - {"nswap", "NSWAP", NULL, USER, rvar, 4, 0, ROFF(ru_nswap), LONG, "d"}, - {"nvcsw", "NVCSW", NULL, USER, rvar, 5, 0, ROFF(ru_nvcsw), LONG, "d"}, + {"nsigs", "NSIGS", NULL, USER, pvar, 4, 0, POFF(p_uru_nsignals), UINT64, "lld"}, + {"nswap", "NSWAP", NULL, USER, pvar, 4, 0, POFF(p_uru_nswap), UINT64, "lld"}, + {"nvcsw", "NVCSW", NULL, USER, pvar, 5, 0, POFF(p_uru_nvcsw), UINT64, "lld"}, /* XXX */ - {"nwchan", "WCHAN", NULL, 0, pvar, 6, 0, POFF(p_wchan), KPTR, "x"}, - {"oublk", "OUBLK", NULL, USER, rvar, 4, 0, ROFF(ru_oublock), LONG, "d"}, + {"nwchan", "WCHAN", NULL, 0, pvar, 6, 0, POFF(p_wchan), UINT64, "llx"}, + {"oublk", "OUBLK", NULL, USER, pvar, 4, 0, POFF(p_uru_oublock), UINT64, "lld"}, {"oublock", "", "oublk"}, /* XXX */ - {"p_ru", "P_RU", NULL, 0, pvar, 6, 0, POFF(p_ru), KPTR, "x"}, + {"p_ru", "P_RU", NULL, 0, pvar, 6, 0, POFF(p_ru), UINT64, "llx"}, /* XXX */ - {"paddr", "PADDR", NULL, 0, evar, 6, 0, EOFF(e_paddr), KPTR, "x"}, + {"paddr", "PADDR", NULL, 0, pvar, 6, 0, POFF(p_paddr), UINT64, "llx"}, {"pagein", "PAGEIN", NULL, USER, pagein, 6}, {"pcpu", "", "%cpu"}, {"pending", "", "sig"}, - PID("pgid", "PGID", evar, EOFF(e_pgid)), + PID("pgid", "PGID", pvar, POFF(p__pgid)), PID("pid", "PID", pvar, POFF(p_pid)), {"pmem", "", "%mem"}, - PID("ppid", "PPID", evar, EOFF(e_ppid)), + PID("ppid", "PPID", pvar, POFF(p_ppid)), {"pri", "PRI", NULL, 0, pri, 3}, - {"re", "RE", NULL, INF127, pvar, 3, 0, POFF(p_swtime), UINT, "d"}, - GID("rgid", "RGID", evar, EOFF(e_pcred.p_rgid)), + {"re", "RE", NULL, INF127, pvar, 3, 0, POFF(p_swtime), UINT32, "u"}, + GID("rgid", "RGID", pvar, POFF(p_rgid)), /* XXX */ {"rgroup", "RGROUP", NULL, LJUST, rgname, USERLEN}, - {"rlink", "RLINK", NULL, 0, pvar, 8, 0, POFF(p_back), KPTR, "x"}, + {"rlink", "RLINK", NULL, 0, pvar, 8, 0, POFF(p_back), UINT64, "llx"}, {"rss", "RSS", NULL, 0, p_rssize, 5}, {"rssize", "", "rsz"}, {"rsz", "RSZ", NULL, 0, rssize, 4}, - UID("ruid", "RUID", evar, EOFF(e_pcred.p_ruid)), + UID("ruid", "RUID", pvar, POFF(p_ruid)), {"ruser", "RUSER", NULL, LJUST, runame, USERLEN}, - {"sess", "SESS", NULL, 0, evar, 6, 0, EOFF(e_sess), KPTR, "x"}, - {"sig", "PENDING", NULL, 0, pvar, 8, 0, POFF(p_siglist), INT, "x"}, - {"sigcatch", "CAUGHT", NULL, 0, pvar, 8, 0, POFF(p_sigcatch), UINT, "x"}, + {"sess", "SESS", NULL, 0, pvar, 6, 0, POFF(p_sess), UINT64, "llx"}, + {"sig", "PENDING", NULL, 0, pvar, 8, 0, POFF(p_siglist), INT32, "x"}, + {"sigcatch", "CAUGHT", NULL, 0, pvar, 8, 0, POFF(p_sigcatch), UINT32, "x"}, {"sigignore", "IGNORED", - NULL, 0, pvar, 8, 0, POFF(p_sigignore), UINT, "x"}, - {"sigmask", "BLOCKED", NULL, 0, pvar, 8, 0, POFF(p_sigmask), UINT, "x"}, - {"sl", "SL", NULL, INF127, pvar, 3, 0, POFF(p_slptime), UINT, "d"}, + NULL, 0, pvar, 8, 0, POFF(p_sigignore), UINT32, "x"}, + {"sigmask", "BLOCKED", NULL, 0, pvar, 8, 0, POFF(p_sigmask), UINT32, "x"}, + {"sl", "SL", NULL, INF127, pvar, 3, 0, POFF(p_slptime), UINT32, "u"}, {"ssiz", "SSIZ", NULL, 0, ssize, 4}, {"start", "STARTED", NULL, LJUST|USER, started, 8}, {"stat", "", "state"}, {"state", "STAT", NULL, 0, state, 5}, - GID("svgid", "SVGID", evar, EOFF(e_pcred.p_svgid)), - UID("svuid", "SVUID", evar, EOFF(e_pcred.p_svuid)), + GID("svgid", "SVGID", pvar, POFF(p_svgid)), + UID("svuid", "SVUID", pvar, POFF(p_svuid)), {"tdev", "TDEV", NULL, 0, tdev, 4}, {"time", "TIME", NULL, USER, cputime, 9}, - PID("tpgid", "TPGID", evar, EOFF(e_tpgid)), - {"tsess", "TSESS", NULL, 0, evar, 6, 0, EOFF(e_tsess), KPTR, "x"}, + PID("tpgid", "TPGID", pvar, POFF(p_tpgid)), + {"tsess", "TSESS", NULL, 0, pvar, 6, 0, POFF(p_tsess), UINT64, "llx"}, {"tsiz", "TSIZ", NULL, 0, tsize, 4}, {"tt", "TT", NULL, LJUST, tname, 3}, {"tty", "TTY", NULL, LJUST, longtname, 8}, {"ucomm", "UCOMM", NULL, LJUST, ucomm, MAXCOMLEN}, - UID("uid", "UID", evar, EOFF(e_ucred.cr_uid)), - {"upr", "UPR", NULL, 0, pvar, 3, 0, POFF(p_usrpri), UCHAR, "d"}, + UID("uid", "UID", pvar, POFF(p_uid)), + {"upr", "UPR", NULL, 0, pvar, 3, 0, POFF(p_usrpri), UINT8, "d"}, {"user", "USER", NULL, LJUST, uname, USERLEN}, {"usrpri", "", "upr"}, {"vsize", "", "vsz"}, {"vsz", "VSZ", NULL, 0, vsize, 5}, {"wchan", "WCHAN", NULL, LJUST, wchan, 6}, - {"xstat", "XSTAT", NULL, 0, pvar, 4, 0, POFF(p_xstat), USHORT, "x"}, + {"xstat", "XSTAT", NULL, 0, pvar, 4, 0, POFF(p_xstat), UINT16, "x"}, {""}, }; diff --git a/bin/ps/print.c b/bin/ps/print.c index a6cbd76acb5..eea52cdd025 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.31 2003/06/11 23:42:12 deraadt Exp $ */ +/* $OpenBSD: print.c,v 1.32 2004/01/08 18:18:35 millert Exp $ */ /* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #else -static char rcsid[] = "$OpenBSD: print.c,v 1.31 2003/06/11 23:42:12 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.32 2004/01/08 18:18:35 millert Exp $"; #endif #endif /* not lint */ @@ -100,7 +100,7 @@ printheader(void) } void -command(KINFO *ki, VARENT *ve) +command(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; int left; @@ -117,7 +117,7 @@ command(KINFO *ki, VARENT *ve) } else left = -1; if (needenv && kd != NULL) { - argv = kvm_getenvv(kd, ki->ki_p, termwidth); + argv = kvm_getenvv2(kd, kp, termwidth); if ((p = argv) != NULL) { while (*p) { fmt_puts(*p, &left); @@ -130,7 +130,7 @@ command(KINFO *ki, VARENT *ve) if (needcomm) { if (!commandonly) { if (kd != NULL) { - argv = kvm_getargv(kd, ki->ki_p, termwidth); + argv = kvm_getargv2(kd, kp, termwidth); if ((p = argv) != NULL) { while (*p) { fmt_puts(*p, &left); @@ -140,13 +140,13 @@ command(KINFO *ki, VARENT *ve) } } if (argv == NULL || argv[0] == '\0' || - strcmp(cmdpart(argv[0]), KI_PROC(ki)->p_comm)) { + strcmp(cmdpart(argv[0]), kp->p_comm)) { fmt_putc('(', &left); - fmt_puts(KI_PROC(ki)->p_comm, &left); + fmt_puts(kp->p_comm, &left); fmt_putc(')', &left); } } else { - fmt_puts(KI_PROC(ki)->p_comm, &left); + fmt_puts(kp->p_comm, &left); } } if (ve->next && left > 0) @@ -154,23 +154,23 @@ command(KINFO *ki, VARENT *ve) } void -ucomm(KINFO *k, VARENT *ve) +ucomm(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%-*s", v->width, KI_PROC(k)->p_comm); + (void)printf("%-*s", v->width, kp->p_comm); } void -logname(KINFO *k, VARENT *ve) +logname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - if (KI_EPROC(k)->e_login[0]) { + if (kp->p_login[0]) { int n = min(v->width, MAXLOGNAME); - (void)printf("%-*.*s", n, n, KI_EPROC(k)->e_login); + (void)printf("%-*.*s", n, n, kp->p_login); if (v->width > n) (void)printf("%*s", v->width - n, ""); } else @@ -180,20 +180,18 @@ logname(KINFO *k, VARENT *ve) #define pgtok(a) (((a)*getpagesize())/1024) void -state(KINFO *k, VARENT *ve) +state(const struct kinfo_proc2 *kp, VARENT *ve) { - struct proc *p; int flag; char *cp; VAR *v; char buf[16]; v = ve->var; - p = KI_PROC(k); - flag = p->p_flag; + flag = kp->p_flag; cp = buf; - switch (p->p_stat) { + switch (kp->p_stat) { case SSTOP: *cp = 'T'; @@ -201,7 +199,7 @@ state(KINFO *k, VARENT *ve) case SSLEEP: if (flag & P_SINTR) /* interruptible (long) */ - *cp = p->p_slptime >= maxslp ? 'I' : 'S'; + *cp = kp->p_slptime >= maxslp ? 'I' : 'S'; else *cp = 'D'; break; @@ -222,92 +220,92 @@ state(KINFO *k, VARENT *ve) if (flag & P_INMEM) { } else *cp++ = 'W'; - if (p->p_nice < NZERO) + if (kp->p_nice < NZERO) *cp++ = '<'; - else if (p->p_nice > NZERO) + else if (kp->p_nice > NZERO) *cp++ = 'N'; if (flag & P_TRACED) *cp++ = 'X'; if (flag & P_SYSTRACE) *cp++ = 'x'; - if (flag & P_WEXIT && p->p_stat != SZOMB) + if (flag & P_WEXIT && kp->p_stat != SZOMB) *cp++ = 'E'; if (flag & P_PPWAIT) *cp++ = 'V'; if (flag & P_SYSTEM) *cp++ = 'K'; /* XXX Since P_SYSTEM now shows a K, should L just be for holdcnt? */ - if ((flag & P_SYSTEM) || p->p_holdcnt) + if ((flag & P_SYSTEM) || kp->p_holdcnt) *cp++ = 'L'; if ((flag & P_SYSTEM) == 0 && - KI_EPROC(k)->e_maxrss / 1024 < pgtok(KI_EPROC(k)->e_vm.vm_rssize)) + kp->p_rlim_rss_cur / 1024 < pgtok(kp->p_vm_rssize)) *cp++ = '>'; - if (KI_EPROC(k)->e_flag & EPROC_SLEADER) + if (kp->p_eflag & EPROC_SLEADER) *cp++ = 's'; - if ((flag & P_CONTROLT) && KI_EPROC(k)->e_pgid == KI_EPROC(k)->e_tpgid) + if ((flag & P_CONTROLT) && kp->p__pgid == kp->p_tpgid) *cp++ = '+'; *cp = '\0'; (void)printf("%-*s", v->width, buf); } void -pri(KINFO *k, VARENT *ve) +pri(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO); + (void)printf("%*d", v->width, kp->p_priority - PZERO); } void -uname(KINFO *k, VARENT *ve) +uname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; (void)printf("%-*s", - (int)v->width, user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0)); + (int)v->width, user_from_uid(kp->p_uid, 0)); } void -runame(KINFO *k, VARENT *ve) +runame(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; (void)printf("%-*s", - (int)v->width, user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0)); + (int)v->width, user_from_uid(kp->p_ruid, 0)); } void -gname(KINFO *k, VARENT *ve) +gname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; (void)printf("%-*s", - (int)v->width, group_from_gid(KI_EPROC(k)->e_ucred.cr_gid, 0)); + (int)v->width, group_from_gid(kp->p_gid, 0)); } void -rgname(KINFO *k, VARENT *ve) +rgname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; (void)printf("%-*s", - (int)v->width, group_from_gid(KI_EPROC(k)->e_pcred.p_rgid, 0)); + (int)v->width, group_from_gid(kp->p_rgid, 0)); } void -tdev(KINFO *k, VARENT *ve) +tdev(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; dev_t dev; char buff[16]; v = ve->var; - dev = KI_EPROC(k)->e_tdev; + dev = kp->p_tdev; if (dev == NODEV) (void)printf("%*s", v->width, "??"); else { @@ -318,33 +316,33 @@ tdev(KINFO *k, VARENT *ve) } void -tname(KINFO *k, VARENT *ve) +tname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; dev_t dev; char *ttname; v = ve->var; - dev = KI_EPROC(k)->e_tdev; + dev = kp->p_tdev; if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) (void)printf("%-*s", v->width, "??"); else { if (strncmp(ttname, "tty", 3) == 0) ttname += 3; (void)printf("%*.*s%c", v->width-1, v->width-1, ttname, - KI_EPROC(k)->e_flag & EPROC_CTTY ? ' ' : '-'); + kp->p_eflag & EPROC_CTTY ? ' ' : '-'); } } void -longtname(KINFO *k, VARENT *ve) +longtname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; dev_t dev; char *ttname; v = ve->var; - dev = KI_EPROC(k)->e_tdev; + dev = kp->p_tdev; if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) (void)printf("%-*s", v->width, "??"); else @@ -352,7 +350,7 @@ longtname(KINFO *k, VARENT *ve) } void -started(KINFO *k, VARENT *ve) +started(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; static time_t now; @@ -361,18 +359,18 @@ started(KINFO *k, VARENT *ve) char buf[100]; v = ve->var; - if (!k->ki_u.u_valid) { + if (!kp->p_uvalid) { (void)printf("%-*s", v->width, "-"); return; } - startt = k->ki_u.u_start.tv_sec; + startt = kp->p_ustart_sec; tp = localtime(&startt); if (!now) (void)time(&now); - if (now - k->ki_u.u_start.tv_sec < 24 * SECSPERHOUR) { + if (now - kp->p_ustart_sec < 24 * SECSPERHOUR) { (void)strftime(buf, sizeof(buf) - 1, "%l:%M%p", tp); - } else if (now - k->ki_u.u_start.tv_sec < 7 * SECSPERDAY) { + } else if (now - kp->p_ustart_sec < 7 * SECSPERDAY) { (void)strftime(buf, sizeof(buf) - 1, "%a%I%p", tp); } else (void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp); @@ -380,78 +378,77 @@ started(KINFO *k, VARENT *ve) } void -lstarted(KINFO *k, VARENT *ve) +lstarted(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; time_t startt; char buf[100]; v = ve->var; - if (!k->ki_u.u_valid) { + if (!kp->p_uvalid) { (void)printf("%-*s", v->width, "-"); return; } - startt = k->ki_u.u_start.tv_sec; + startt = kp->p_ustart_sec; (void)strftime(buf, sizeof(buf) -1, "%c", localtime(&startt)); (void)printf("%-*s", v->width, buf); } void -wchan(KINFO *k, VARENT *ve) +wchan(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - if (KI_PROC(k)->p_wchan) { + if (kp->p_wchan) { int n; - if (KI_PROC(k)->p_wmesg) { + if (kp->p_wmesg) { n = min(v->width, WMESGLEN); - (void)printf("%-*.*s", n, n, KI_EPROC(k)->e_wmesg); + (void)printf("%-*.*s", n, n, kp->p_wmesg); if (v->width > n) (void)printf("%*s", v->width - n, ""); } else (void)printf("%-*lx", v->width, - (long)KI_PROC(k)->p_wchan &~ KERNBASE); + (long)kp->p_wchan &~ KERNBASE); } else (void)printf("%-*s", v->width, "-"); } void -vsize(KINFO *k, VARENT *ve) +vsize(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; (void)printf("%*d", v->width, - pgtok(KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize + - KI_EPROC(k)->e_vm.vm_tsize)); + pgtok(kp->p_vm_dsize + kp->p_vm_ssize + kp->p_vm_tsize)); } void -rssize(KINFO *k, VARENT *ve) +rssize(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; /* XXX don't have info about shared */ - (void)printf("%*d", v->width, (KI_PROC(k)->p_flag & P_SYSTEM) ? 0 : - pgtok(KI_EPROC(k)->e_vm.vm_rssize)); + (void)printf("%*d", v->width, (kp->p_flag & P_SYSTEM) ? 0 : + pgtok(kp->p_vm_rssize)); } void -p_rssize(KINFO *k, VARENT *ve) +p_rssize(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*d", v->width, (KI_PROC(k)->p_flag & P_SYSTEM) ? 0 : - pgtok(KI_EPROC(k)->e_vm.vm_rssize)); + (void)printf("%*d", v->width, (kp->p_flag & P_SYSTEM) ? 0 : + pgtok(kp->p_vm_rssize)); } void -cputime(KINFO *k, VARENT *ve) +cputime(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; long secs; @@ -459,7 +456,7 @@ cputime(KINFO *k, VARENT *ve) char obuff[128]; v = ve->var; - if (KI_PROC(k)->p_stat == SZOMB || !k->ki_u.u_valid) { + if (kp->p_stat == SZOMB || !kp->p_uvalid) { secs = 0; psecs = 0; } else { @@ -468,13 +465,11 @@ cputime(KINFO *k, VARENT *ve) * 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; + secs = kp->p_rtime_sec; + psecs = kp->p_rtime_usec; if (sumrusage) { - secs += k->ki_u.u_cru.ru_utime.tv_sec + - k->ki_u.u_cru.ru_stime.tv_sec; - psecs += k->ki_u.u_cru.ru_utime.tv_usec + - k->ki_u.u_cru.ru_stime.tv_usec; + secs += kp->p_uctime_sec; + psecs += kp->p_uctime_usec; } /* * round and scale to 100's @@ -489,9 +484,8 @@ cputime(KINFO *k, VARENT *ve) } double -getpcpu(KINFO *k) +getpcpu(const struct kinfo_proc2 *kp) { - struct proc *p; static int failure; double d; @@ -500,41 +494,38 @@ getpcpu(KINFO *k) if (failure) return (0.0); - p = KI_PROC(k); #define fxtofl(fixpt) ((double)(fixpt) / fscale) /* XXX - I don't like this */ - if (p->p_swtime == 0 || (p->p_flag & P_INMEM) == 0) + if (kp->p_swtime == 0 || (kp->p_flag & P_INMEM) == 0) return (0.0); if (rawcpu) - return (100.0 * fxtofl(p->p_pctcpu)); + return (100.0 * fxtofl(kp->p_pctcpu)); - d = p->p_swtime * log(fxtofl(ccpu)); + d = kp->p_swtime * log(fxtofl(ccpu)); if (d < -700.0) d = 0.0; /* avoid IEEE underflow */ else d = exp(d); if (d == 1.0) return (0.0); - return (100.0 * fxtofl(p->p_pctcpu) / + return (100.0 * fxtofl(kp->p_pctcpu) / (1.0 - d)); } void -pcpu(KINFO *k, VARENT *ve) +pcpu(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*.1f", v->width, getpcpu(k)); + (void)printf("%*.1f", v->width, getpcpu(kp)); } double -getpmem(KINFO *k) +getpmem(const struct kinfo_proc2 *kp) { static int failure; - struct proc *p; - struct eproc *e; double fracmem; int szptudot; @@ -543,70 +534,68 @@ getpmem(KINFO *k) if (failure) return (0.0); - p = KI_PROC(k); - e = KI_EPROC(k); - if ((p->p_flag & P_INMEM) == 0 || (p->p_flag & P_SYSTEM)) + if ((kp->p_flag & P_INMEM) == 0 || (kp->p_flag & P_SYSTEM)) return (0.0); /* XXX want pmap ptpages, segtab, etc. (per architecture) */ szptudot = USPACE/getpagesize(); /* XXX don't have info about shared */ - fracmem = ((float)e->e_vm.vm_rssize + szptudot)/mempages; + fracmem = ((float)kp->p_vm_rssize + szptudot)/mempages; return (100.0 * fracmem); } void -pmem(KINFO *k, VARENT *ve) +pmem(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*.1f", v->width, getpmem(k)); + (void)printf("%*.1f", v->width, getpmem(kp)); } void -pagein(KINFO *k, VARENT *ve) +pagein(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*ld", v->width, - k->ki_u.u_valid ? k->ki_u.u_ru.ru_majflt : 0); + (void)printf("%*llu", v->width, + kp->p_uvalid ? kp->p_uru_majflt : 0); } void -maxrss(KINFO *k, VARENT *ve) +maxrss(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*lld", v->width, KI_EPROC(k)->e_maxrss / 1024); + (void)printf("%*lld", v->width, kp->p_rlim_rss_cur / 1024); } void -tsize(KINFO *k, VARENT *ve) +tsize(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_tsize)); + (void)printf("%*d", v->width, pgtok(kp->p_vm_tsize)); } void -dsize(KINFO *k, VARENT *ve) +dsize(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_dsize)); + (void)printf("%*d", v->width, pgtok(kp->p_vm_dsize)); } void -ssize(KINFO *k, VARENT *ve) +ssize(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_ssize)); + (void)printf("%*d", v->width, pgtok(kp->p_vm_ssize)); } /* @@ -616,16 +605,10 @@ ssize(KINFO *k, VARENT *ve) static void printval(char *bp, VAR *v) { - static char ofmt[32] = "%"; - char *fcp, *cp; - enum type type; + char ofmt[32]; - cp = ofmt + 1; - fcp = v->fmt; - if (v->flag & LJUST) - *cp++ = '-'; - *cp++ = '*'; - while ((*cp++ = *fcp++)); + snprintf(ofmt, sizeof(ofmt), "%%%s*%s", (v->flag & LJUST) ? "-" : "", + v->fmt); /* * Note that the "INF127" check is nonsensical for types @@ -635,54 +618,28 @@ printval(char *bp, VAR *v) #define CHK_INF127(n) (((n) > 127) && (v->flag & INF127) ? 127 : (n)) switch (v->type) { - case INT32: - if (sizeof(int32_t) == sizeof(int)) - type = INT; - else if (sizeof(int32_t) == sizeof(long)) - type = LONG; - else - errx(1, "unknown conversion for type %d", v->type); - break; - case UINT32: - if (sizeof(u_int32_t) == sizeof(u_int)) - type = UINT; - else if (sizeof(u_int32_t) == sizeof(u_long)) - type = ULONG; - else - errx(1, "unknown conversion for type %d", v->type); - break; - default: - type = v->type; - break; - } - - switch (type) { - case CHAR: - (void)printf(ofmt, v->width, GET(char)); + case INT8: + (void)printf(ofmt, v->width, GET(int8_t)); break; - case UCHAR: - (void)printf(ofmt, v->width, CHK_INF127(GET(u_char))); + case UINT8: + (void)printf(ofmt, v->width, CHK_INF127(GET(u_int8_t))); break; - case SHORT: - (void)printf(ofmt, v->width, GET(short)); + case INT16: + (void)printf(ofmt, v->width, GET(int16_t)); break; - case USHORT: - (void)printf(ofmt, v->width, CHK_INF127(GET(u_short))); + case UINT16: + (void)printf(ofmt, v->width, CHK_INF127(GET(u_int16_t))); break; - case INT: - (void)printf(ofmt, v->width, GET(int)); - break; - case UINT: - (void)printf(ofmt, v->width, CHK_INF127(GET(u_int))); - break; - case LONG: - (void)printf(ofmt, v->width, GET(long)); + case INT32: + (void)printf(ofmt, v->width, GET(int32_t)); break; - case ULONG: - (void)printf(ofmt, v->width, CHK_INF127(GET(u_long))); + case UINT32: + (void)printf(ofmt, v->width, CHK_INF127(GET(u_int32_t))); break; - case KPTR: - (void)printf(ofmt, v->width, GET(u_long) &~ KERNBASE); + case INT64: + (void)printf(ofmt, v->width, GET(int64_t)); + case UINT64: + (void)printf(ofmt, v->width, CHK_INF127(GET(u_int64_t))); break; default: errx(1, "unknown type %d", v->type); @@ -692,54 +649,23 @@ printval(char *bp, VAR *v) } void -pvar(KINFO *k, VARENT *ve) -{ - VAR *v; - - v = ve->var; - printval((char *)((char *)KI_PROC(k) + v->off), v); -} - -void -evar(KINFO *k, VARENT *ve) -{ - VAR *v; - - v = ve->var; - printval((char *)((char *)KI_EPROC(k) + v->off), v); -} - -void -uvar(KINFO *k, VARENT *ve) +pvar(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - if (k->ki_u.u_valid) - printval((char *)((char *)&k->ki_u + v->off), v); - else + if ((v->flag & USER) && !kp->p_uvalid) (void)printf("%*s", v->width, "-"); -} - -void -rvar(KINFO *k, VARENT *ve) -{ - VAR *v; - - v = ve->var; - if (k->ki_u.u_valid) - printval((char *)((char *)(&k->ki_u.u_ru) + v->off), v); else - (void)printf("%*s", v->width, "-"); + printval((char *)kp + v->off, v); } void -emulname(KINFO *k, VARENT *ve) +emulname(const struct kinfo_proc2 *kp, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%-*s", - (int)v->width, KI_EPROC(k)->e_emul); + (void)printf("%-*s", (int)v->width, kp->p_emul); } diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 644b111a089..385d990e357 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.34 2003/07/29 00:24:15 deraadt Exp $ */ +/* $OpenBSD: ps.c,v 1.35 2004/01/08 18:18:35 millert Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -40,7 +40,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: ps.c,v 1.34 2003/07/29 00:24:15 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: ps.c,v 1.35 2004/01/08 18:18:35 millert Exp $"; #endif #endif /* not lint */ @@ -72,7 +72,6 @@ static char rcsid[] = "$OpenBSD: ps.c,v 1.34 2003/07/29 00:24:15 deraadt Exp $"; extern char *__progname; -KINFO *kinfo; struct varent *vhead, *vtail; int eval; /* exit value */ @@ -87,7 +86,6 @@ enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; static char *kludge_oldps_options(char *); static int pscomp(const void *, const void *); -static void saveuser(KINFO *); static void scanvars(void); static void usage(void); @@ -105,14 +103,14 @@ int kvm_sysctl_only; int main(int argc, char *argv[]) { - struct kinfo_proc *kp; + struct kinfo_proc2 *kp, **kinfo; struct varent *vent; struct winsize ws; struct passwd *pwd; dev_t ttydev; pid_t pid; uid_t uid; - int all, ch, flag, i, fmt, lineno, nentries, mib[4], mibcnt, nproc; + int all, ch, flag, i, fmt, lineno, nentries, mib[6]; int prtheader, wflag, kflag, what, xflg; char *nlistf, *memf, *swapf, errbuf[_POSIX2_LINE_MAX]; size_t size; @@ -297,56 +295,51 @@ main(int argc, char *argv[]) * get proc list */ if (uid != (uid_t) -1) { - what = mib[2] = KERN_PROC_UID; - flag = mib[3] = uid; - mibcnt = 4; + what = KERN_PROC_UID; + flag = uid; } else if (ttydev != NODEV) { - what = mib[2] = KERN_PROC_TTY; - flag = mib[3] = ttydev; - mibcnt = 4; + what = KERN_PROC_TTY; + flag = ttydev; } else if (pid != -1) { - what = mib[2] = KERN_PROC_PID; - flag = mib[3] = pid; - mibcnt = 4; + what = KERN_PROC_PID; + flag = pid; } else if (kflag) { - what = mib[2] = KERN_PROC_KTHREAD; + what = KERN_PROC_KTHREAD; flag = 0; - mibcnt = 3; } else { - what = mib[2] = KERN_PROC_ALL; + what = KERN_PROC_ALL; flag = 0; - mibcnt = 3; } /* * select procs */ if (kd != NULL) { - if ((kp = kvm_getprocs(kd, what, flag, &nentries)) == 0) + kp = kvm_getproc2(kd, what, flag, sizeof(*kp), &nentries); + if (kp == NULL) errx(1, "%s", kvm_geterr(kd)); - } - else { + } else { mib[0] = CTL_KERN; - mib[1] = KERN_NPROCS; - size = sizeof (nproc); - if (sysctl(mib, 2, &nproc, &size, NULL, 0) < 0) - err(1, "could not get kern.nproc"); - /* Allocate more memory than is needed, just in case */ - size = (5 * nproc * sizeof(struct kinfo_proc)) / 4; - kp = calloc(size, sizeof(char)); - if (kp == NULL) + mib[1] = KERN_PROC2; + mib[2] = what; + mib[3] = flag; + mib[4] = sizeof(struct kinfo_proc2); + mib[5] = 0; + retry: + if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) + err(1, "could not get kern.proc2 size"); + size = 5 * size / 4; /* extra slop */ + if ((kp = malloc(size)) == NULL) err(1, - "failed to allocated memory for proc structures"); - mib[1] = KERN_PROC; - if (sysctl(mib, mibcnt, kp, &size, NULL, 0) < 0) - err(1, "could not read kern.proc"); - nentries = size / sizeof(struct kinfo_proc); - } - - if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL) - err(1, NULL); - for (i = nentries; --i >= 0; ++kp) { - kinfo[i].ki_p = kp; - saveuser(&kinfo[i]); + "failed to allocate memory for proc structures"); + mib[5] = (int)(size / sizeof(struct kinfo_proc2)); + if (sysctl(mib, 6, kp, &size, NULL, 0) < 0) { + if (errno == ENOMEM) { + free(kp); + goto retry; + } + err(1, "could not read kern.proc2"); + } + nentries = (int)(size / sizeof(struct kinfo_proc2)); } /* * print header @@ -355,20 +348,23 @@ main(int argc, char *argv[]) if (nentries == 0) exit(1); /* - * sort proc list + * sort proc list, we convert from an array of structs to an array + * of pointers to make the sort cheaper. */ - qsort(kinfo, nentries, sizeof(KINFO), pscomp); + if ((kinfo = malloc(sizeof(*kinfo) * nentries)) == NULL) + err(1, "failed to allocate memory for proc pointers"); + for (i = 0; i < nentries; i++) + kinfo[i] = &kp[i]; + qsort(kinfo, nentries, sizeof(*kinfo), pscomp); /* * for each proc, call each variable output function. */ for (i = lineno = 0; i < nentries; i++) { - KINFO *ki = &kinfo[i]; - - if (xflg == 0 && (KI_EPROC(ki)->e_tdev == NODEV || - (KI_PROC(ki)->p_flag & P_CONTROLT ) == 0)) + if (xflg == 0 && (kinfo[i]->p_tdev == NODEV || + (kinfo[i]->p_flag & P_CONTROLT ) == 0)) continue; for (vent = vhead; vent; vent = vent->next) { - (vent->var->oproc)(ki, vent); + (vent->var->oproc)(kinfo[i], vent); if (vent->next != NULL) (void)putchar(' '); } @@ -401,38 +397,21 @@ scanvars(void) totwidth--; } -static void -saveuser(KINFO *ki) -{ - struct usave *usp; - - usp = &ki->ki_u; - usp->u_valid = KI_EPROC(ki)->e_pstats_valid; - if (!usp->u_valid) - return; - usp->u_start = KI_EPROC(ki)->e_pstats.p_start; - usp->u_ru = KI_EPROC(ki)->e_pstats.p_ru; - usp->u_cru = KI_EPROC(ki)->e_pstats.p_cru; -} - static int -pscomp(const void *a, const void *b) +pscomp(const void *v1, const void *v2) { + const struct kinfo_proc2 *kp1 = *(const struct kinfo_proc2 **)v1; + const struct kinfo_proc2 *kp2 = *(const struct kinfo_proc2 **)v2; int i; -#define VSIZE(k) (KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize + \ - KI_EPROC(k)->e_vm.vm_tsize) -#define STARTTIME(k) (k->ki_u.u_start.tv_sec) -#define STARTuTIME(k) (k->ki_u.u_start.tv_usec) - - if (sortby == SORTCPU) - return (getpcpu((KINFO *)b) - getpcpu((KINFO *)a)); - if (sortby == SORTMEM) - return (VSIZE((KINFO *)b) - VSIZE((KINFO *)a)); - i = KI_EPROC((KINFO *)a)->e_tdev - KI_EPROC((KINFO *)b)->e_tdev; - if (i == 0) - i = STARTTIME(((KINFO *)a)) - STARTTIME(((KINFO *)b)); - if (i == 0) - i = STARTuTIME(((KINFO *)a)) - STARTuTIME(((KINFO *)b)); +#define VSIZE(k) ((k)->p_vm_dsize + (k)->p_vm_ssize + (k)->p_vm_tsize) + + if (sortby == SORTCPU && (i = getpcpu(kp2) - getpcpu(kp1)) != 0) + return (i); + if (sortby == SORTMEM && (i = VSIZE(kp2) - VSIZE(kp1)) != 0) + return (i); + if ((i = kp1->p_tdev - kp2->p_tdev) == 0 && + (i = kp1->p_ustart_sec - kp2->p_ustart_sec) == 0) + i = kp1->p_ustart_usec - kp2->p_ustart_usec; return (i); } diff --git a/bin/ps/ps.h b/bin/ps/ps.h index 93e1f8d644a..43f18e9b069 100644 --- a/bin/ps/ps.h +++ b/bin/ps/ps.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.h,v 1.5 2003/06/02 23:32:09 millert Exp $ */ +/* $OpenBSD: ps.h,v 1.6 2004/01/08 18:18:35 millert Exp $ */ /* $NetBSD: ps.h,v 1.11 1995/09/29 21:57:03 cgd Exp $ */ /*- @@ -34,8 +34,7 @@ #define UNLIMITED 0 /* unlimited terminal width */ enum type { - CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, - INT32, UINT32 + INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64 }; struct usave { @@ -46,20 +45,13 @@ struct usave { char u_valid; }; -#define KI_PROC(ki) (&(ki)->ki_p->kp_proc) -#define KI_EPROC(ki) (&(ki)->ki_p->kp_eproc) - -typedef struct kinfo { - struct kinfo_proc *ki_p; /* proc structure */ - struct usave ki_u; /* interesting parts of user */ -} KINFO; - /* Variables. */ typedef struct varent { struct varent *next; struct var *var; } VARENT; +struct kinfo_proc2; typedef struct var { char *name; /* name(s) of variable */ char *header; /* default header */ @@ -70,7 +62,7 @@ typedef struct var { #define INF127 0x08 /* 127 = infinity: if > 127, print 127. */ u_int flag; /* output routine */ - void (*oproc)(struct kinfo *, struct varent *); + void (*oproc)(const struct kinfo_proc2 *, struct varent *); short width; /* printing width */ char parsed; /* have we been parsed yet? (avoid dupes) */ /* |