summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2000-12-12 07:25:57 +0000
committermckusick <mckusick@FreeBSD.org>2000-12-12 07:25:57 +0000
commitcba301121bc106aaff382428a55f31fef30844e6 (patch)
tree910e5652e5d16d5d0d4e8480f7e386aaf0ca310e /bin
parentd577ae457b219ac16b4e152a40ae4d7474c4622f (diff)
downloadFreeBSD-src-cba301121bc106aaff382428a55f31fef30844e6.zip
FreeBSD-src-cba301121bc106aaff382428a55f31fef30844e6.tar.gz
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather only scalar values and structures that are already part of the kernel/user interface, specifically rusage and rtprio. It no longer contains proc, session, pcred, ucred, procsig, vmspace, pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If any of these changed in size, ps, w, fstat, gcore, systat, and top would all stop working. The new structure has over 200 bytes of unassigned space for future values to be added, yet is nearly 100 bytes smaller per entry than the structure that it replaced.
Diffstat (limited to 'bin')
-rw-r--r--bin/ps/extern.h4
-rw-r--r--bin/ps/keyword.c65
-rw-r--r--bin/ps/print.c147
-rw-r--r--bin/ps/ps.c37
-rw-r--r--bin/ps/ps.h19
5 files changed, 103 insertions, 169 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index d184eda..ac4fb2e 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -49,10 +49,10 @@ __BEGIN_DECLS
void command __P((KINFO *, VARENT *));
void cputime __P((KINFO *, VARENT *));
int donlist __P((void));
-void evar __P((KINFO *, VARENT *));
char *fmt_argv __P((char **, char *, int));
double getpcpu __P((KINFO *));
double getpmem __P((KINFO *));
+void kvar __P((KINFO *, VARENT *));
void logname __P((KINFO *, VARENT *));
void longtname __P((KINFO *, VARENT *));
void lstarted __P((KINFO *, VARENT *));
@@ -67,7 +67,6 @@ void pmem __P((KINFO *, VARENT *));
void pri __P((KINFO *, VARENT *));
void rtprior __P((KINFO *, VARENT *));
void printheader __P((void));
-void pvar __P((KINFO *, VARENT *));
void rssize __P((KINFO *, VARENT *));
void runame __P((KINFO *, VARENT *));
int s_runame __P((KINFO *));
@@ -81,7 +80,6 @@ void tsize __P((KINFO *, VARENT *));
void ucomm __P((KINFO *, VARENT *));
void uname __P((KINFO *, VARENT *));
int s_uname __P((KINFO *));
-void uvar __P((KINFO *, VARENT *));
void vsize __P((KINFO *, VARENT *));
void wchan __P((KINFO *, VARENT *));
__END_DECLS
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index de87d40..4fbd98f 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -71,8 +71,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 KOFF(x) offsetof(struct kinfo_proc, x)
#define UOFF(x) offsetof(struct usave, x)
#define ROFF(x) offsetof(struct rusage, x)
@@ -86,24 +85,22 @@ VAR var[] = {
{"%cpu", "%CPU", NULL, 0, pcpu, NULL, 4},
{"%mem", "%MEM", NULL, 0, pmem, NULL, 4},
{"acflag", "ACFLG",
- NULL, 0, pvar, NULL, 3, POFF(p_acflag), USHORT, "x"},
+ NULL, 0, kvar, NULL, 3, KOFF(ki_acflag), USHORT, "x"},
{"acflg", "", "acflag"},
{"blocked", "", "sigmask"},
{"caught", "", "sigcatch"},
{"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16},
- {"cpu", "CPU", NULL, 0, pvar, NULL, 3, POFF(p_estcpu), UINT, "d"},
+ {"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d"},
{"cputime", "", "time"},
- {"f", "F", NULL, 0, pvar, NULL, 7, POFF(p_flag), INT, "x"},
+ {"f", "F", NULL, 0, kvar, NULL, 7, KOFF(ki_flag), INT, "x"},
{"flags", "", "f"},
{"ignored", "", "sigignore"},
{"inblk", "INBLK",
NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG, "ld"},
{"inblock", "", "inblk"},
- {"jobc", "JOBC", NULL, 0, evar, NULL, 4, EOFF(e_jobc), SHORT, "d"},
+ {"jobc", "JOBC", NULL, 0, kvar, NULL, 4, KOFF(ki_jobc), SHORT, "d"},
{"ktrace", "KTRACE",
- NULL, 0, pvar, NULL, 8, POFF(p_traceflag), INT, "x"},
- {"ktracep", "KTRACEP",
- NULL, 0, pvar, NULL, 8, POFF(p_tracep), LONG, "lx"},
+ NULL, 0, kvar, NULL, 8, KOFF(ki_traceflag), INT, "x"},
{"lim", "LIM", NULL, 0, maxrss, NULL, 5},
{"login", "LOGIN", NULL, LJUST, logname, NULL, MAXLOGNAME-1},
{"logname", "", "login"},
@@ -118,7 +115,7 @@ VAR var[] = {
{"msgsnd", "MSGSND",
NULL, USER, rvar, NULL, 4, ROFF(ru_msgsnd), LONG, "ld"},
{"ni", "", "nice"},
- {"nice", "NI", NULL, 0, pvar, NULL, 2, POFF(p_nice), CHAR, "d"},
+ {"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d"},
{"nivcsw", "NIVCSW",
NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw), LONG, "ld"},
{"nsignals", "", "nsigs"},
@@ -128,68 +125,60 @@ VAR var[] = {
NULL, USER, rvar, NULL, 4, ROFF(ru_nswap), LONG, "ld"},
{"nvcsw", "NVCSW",
NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw), LONG, "ld"},
- {"nwchan", "WCHAN", NULL, 0, pvar, NULL, 6, POFF(p_wchan), KPTR, "lx"},
+ {"nwchan", "WCHAN", NULL, 0, kvar, NULL, 6, KOFF(ki_wchan), KPTR, "lx"},
{"oublk", "OUBLK",
NULL, USER, rvar, NULL, 4, ROFF(ru_oublock), LONG, "ld"},
{"oublock", "", "oublk"},
- {"p_ru", "P_RU", NULL, 0, pvar, NULL, 6, POFF(p_ru), KPTR, "lx"},
- {"paddr", "PADDR", NULL, 0, evar, NULL, 6, EOFF(e_paddr), KPTR, "lx"},
+ {"paddr", "PADDR", NULL, 0, kvar, NULL, 6, KOFF(ki_paddr), KPTR, "lx"},
{"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6},
{"pcpu", "", "%cpu"},
{"pending", "", "sig"},
{"pgid", "PGID",
- NULL, 0, evar, NULL, PIDLEN, EOFF(e_pgid), UINT, PIDFMT},
- {"pid", "PID", NULL, 0, pvar, NULL, PIDLEN, POFF(p_pid), UINT, PIDFMT},
+ NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pgid), UINT, PIDFMT},
+ {"pid", "PID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pid), UINT, PIDFMT},
{"pmem", "", "%mem"},
{"ppid", "PPID",
- NULL, 0, evar, NULL, PIDLEN, EOFF(e_ppid), UINT, PIDFMT},
+ NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_ppid), UINT, PIDFMT},
{"pri", "PRI", NULL, 0, pri, NULL, 3},
- {"re", "RE", NULL, 0, pvar, NULL, 3, POFF(p_swtime), UINT, "d"},
- {"rgid", "RGID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_pcred.p_rgid),
+ {"re", "RE", NULL, 0, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d"},
+ {"rgid", "RGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_rgid),
UINT, UIDFMT},
- {"rlink", "RLINK",
- NULL, 0, pvar, NULL, 8, POFF(p_procq.tqe_prev), KPTR, "lx"},
- {"rss", "RSS", NULL, 0, p_rssize, NULL, 4},
- {"rssize", "", "rsz"},
- {"rsz", "RSZ", NULL, 0, rssize, NULL, 4},
- {"rtprio", "RTPRIO", NULL, 0, rtprior, NULL, 7, POFF(p_rtprio)},
- {"ruid", "RUID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_pcred.p_ruid),
+ {"rtprio", "RTPRIO", NULL, 0, rtprior, NULL, 7, KOFF(ki_rtprio)},
+ {"ruid", "RUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_ruid),
UINT, UIDFMT},
{"ruser", "RUSER", NULL, LJUST|DSIZ, runame, s_runame, USERLEN},
- {"sess", "SESS", NULL, 0, evar, NULL, 6, EOFF(e_sess), KPTR, "lx"},
- {"sig", "PENDING", NULL, 0, pvar, NULL, 8, POFF(p_siglist), INT, "x"},
+ {"sig", "PENDING", NULL, 0, kvar, NULL, 8, KOFF(ki_siglist), INT, "x"},
{"sigcatch", "CAUGHT",
- NULL, 0, evar, NULL, 8, EOFF(e_procsig.ps_sigcatch), UINT, "x"},
+ NULL, 0, kvar, NULL, 8, KOFF(ki_sigcatch), UINT, "x"},
{"sigignore", "IGNORED",
- NULL, 0, evar, NULL, 8, EOFF(e_procsig.ps_sigignore), UINT, "x"},
+ NULL, 0, kvar, NULL, 8, KOFF(ki_sigignore), UINT, "x"},
{"sigmask", "BLOCKED",
- NULL, 0, pvar, NULL, 8, POFF(p_sigmask), UINT, "x"},
- {"sl", "SL", NULL, 0, pvar, NULL, 3, POFF(p_slptime), UINT, "d"},
+ NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask), UINT, "x"},
+ {"sl", "SL", NULL, 0, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d"},
{"start", "STARTED", NULL, LJUST|USER, started, NULL, 7},
{"stat", "", "state"},
{"state", "STAT", NULL, 0, state, NULL, 4},
{"svgid", "SVGID", NULL, 0,
- evar, NULL, UIDLEN, EOFF(e_pcred.p_svgid), UINT, UIDFMT},
+ kvar, NULL, UIDLEN, KOFF(ki_svgid), UINT, UIDFMT},
{"svuid", "SVUID", NULL, 0,
- evar, NULL, UIDLEN, EOFF(e_pcred.p_svuid), UINT, UIDFMT},
+ kvar, NULL, UIDLEN, KOFF(ki_svuid), UINT, UIDFMT},
{"tdev", "TDEV", NULL, 0, tdev, NULL, 4},
{"time", "TIME", NULL, USER, cputime, NULL, 9},
{"tpgid", "TPGID",
- NULL, 0, evar, NULL, 4, EOFF(e_tpgid), UINT, PIDFMT},
- {"tsess", "TSESS", NULL, 0, evar, NULL, 6, EOFF(e_tsess), KPTR, "lx"},
+ NULL, 0, kvar, NULL, 4, KOFF(ki_tpgid), UINT, PIDFMT},
{"tsiz", "TSIZ", NULL, 0, tsize, NULL, 4},
{"tt", "TT ", NULL, 0, tname, NULL, 4},
{"tty", "TTY", NULL, LJUST, longtname, NULL, 8},
{"ucomm", "UCOMM", NULL, LJUST, ucomm, NULL, MAXCOMLEN},
- {"uid", "UID", NULL, 0, evar, NULL, UIDLEN, EOFF(e_ucred.cr_uid),
+ {"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid),
UINT, UIDFMT},
- {"upr", "UPR", NULL, 0, pvar, NULL, 3, POFF(p_usrpri), CHAR, "d"},
+ {"upr", "UPR", NULL, 0, kvar, NULL, 3, KOFF(ki_usrpri), CHAR, "d"},
{"user", "USER", NULL, LJUST|DSIZ, uname, s_uname, USERLEN},
{"usrpri", "", "upr"},
{"vsize", "", "vsz"},
{"vsz", "VSZ", NULL, 0, vsize, NULL, 5},
{"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6},
- {"xstat", "XSTAT", NULL, 0, pvar, NULL, 4, POFF(p_xstat), USHORT, "x"},
+ {"xstat", "XSTAT", NULL, 0, kvar, NULL, 4, KOFF(ki_xstat), USHORT, "x"},
{""},
};
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 9b1c913..0ad2b31 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -96,9 +96,9 @@ command(k, ve)
if (cflag) {
if (ve->next == NULL) /* last field, don't pad */
- (void)printf("%s", KI_PROC(k)->p_comm);
+ (void)printf("%s", k->ki_p->ki_comm);
else
- (void)printf("%-*s", v->width, KI_PROC(k)->p_comm);
+ (void)printf("%-*s", v->width, k->ki_p->ki_comm);
return;
}
@@ -147,7 +147,7 @@ ucomm(k, ve)
VAR *v;
v = ve->var;
- (void)printf("%-*s", v->width, KI_PROC(k)->p_comm);
+ (void)printf("%-*s", v->width, k->ki_p->ki_comm);
}
void
@@ -159,7 +159,7 @@ logname(k, ve)
char *s;
v = ve->var;
- (void)printf("%-*s", v->width, (s = KI_EPROC(k)->e_login, *s) ? s : "-");
+ (void)printf("%-*s", v->width, (s = k->ki_p->ki_login, *s) ? s : "-");
}
void
@@ -167,18 +167,16 @@ state(k, ve)
KINFO *k;
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 = k->ki_p->ki_flag;
cp = buf;
- switch (p->p_stat) {
+ switch (k->ki_p->ki_stat) {
case SSTOP:
*cp = 'T';
@@ -186,7 +184,7 @@ state(k, ve)
case SSLEEP:
if (flag & P_SINTR) /* interruptable (long) */
- *cp = p->p_slptime >= MAXSLP ? 'I' : 'S';
+ *cp = k->ki_p->ki_slptime >= MAXSLP ? 'I' : 'S';
else
*cp = 'D';
break;
@@ -214,21 +212,21 @@ state(k, ve)
cp++;
if (!(flag & P_INMEM))
*cp++ = 'W';
- if (p->p_nice < NZERO)
+ if (k->ki_p->ki_nice < NZERO)
*cp++ = '<';
- else if (p->p_nice > NZERO)
+ else if (k->ki_p->ki_nice > NZERO)
*cp++ = 'N';
if (flag & P_TRACED)
*cp++ = 'X';
- if (flag & P_WEXIT && p->p_stat != SZOMB)
+ if (flag & P_WEXIT && k->ki_p->ki_stat != SZOMB)
*cp++ = 'E';
if (flag & P_PPWAIT)
*cp++ = 'V';
- if ((flag & P_SYSTEM) || p->p_lock > 0)
+ if ((flag & P_SYSTEM) || k->ki_p->ki_lock > 0)
*cp++ = 'L';
- if (KI_EPROC(k)->e_flag & EPROC_SLEADER)
+ if (k->ki_p->ki_kiflag & KI_SLEADER)
*cp++ = 's';
- if ((flag & P_CONTROLT) && KI_EPROC(k)->e_pgid == KI_EPROC(k)->e_tpgid)
+ if ((flag & P_CONTROLT) && k->ki_p->ki_pgid == k->ki_p->ki_tpgid)
*cp++ = '+';
if (flag & P_JAILED)
*cp++ = 'J';
@@ -244,7 +242,7 @@ pri(k, ve)
VAR *v;
v = ve->var;
- (void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO);
+ (void)printf("%*d", v->width, k->ki_p->ki_priority - PZERO);
}
void
@@ -256,14 +254,14 @@ uname(k, ve)
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(k->ki_p->ki_uid, 0));
}
int
s_uname(k)
KINFO *k;
{
- return (strlen(user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0)));
+ return (strlen(user_from_uid(k->ki_p->ki_uid, 0)));
}
void
@@ -275,14 +273,14 @@ runame(k, ve)
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(k->ki_p->ki_ruid, 0));
}
int
s_runame(k)
KINFO *k;
{
- return (strlen(user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0)));
+ return (strlen(user_from_uid(k->ki_p->ki_ruid, 0)));
}
void
@@ -295,7 +293,7 @@ tdev(k, ve)
char buff[16];
v = ve->var;
- dev = KI_EPROC(k)->e_tdev;
+ dev = k->ki_p->ki_tdev;
if (dev == NODEV)
(void)printf("%*s", v->width, "??");
else {
@@ -315,7 +313,7 @@ tname(k, ve)
char *ttname;
v = ve->var;
- dev = KI_EPROC(k)->e_tdev;
+ dev = k->ki_p->ki_tdev;
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
(void)printf("%*s ", v->width-1, "??");
else {
@@ -323,7 +321,7 @@ tname(k, ve)
strncmp(ttname, "cua", 3) == 0)
ttname += 3;
(void)printf("%*.*s%c", v->width-1, v->width-1, ttname,
- KI_EPROC(k)->e_flag & EPROC_CTTY ? ' ' : '-');
+ k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-');
}
}
@@ -337,7 +335,7 @@ longtname(k, ve)
char *ttname;
v = ve->var;
- dev = KI_EPROC(k)->e_tdev;
+ dev = k->ki_p->ki_tdev;
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
(void)printf("%-*s", v->width, "??");
else
@@ -356,18 +354,18 @@ started(k, ve)
char buf[100];
v = ve->var;
- if (!k->ki_u.u_valid) {
+ if (!k->ki_valid) {
(void)printf("%-*s", v->width, "-");
return;
}
- then = k->ki_u.u_start.tv_sec;
+ then = k->ki_p->ki_start.tv_sec;
tp = localtime(&then);
if (!now)
(void)time(&now);
- if (now - k->ki_u.u_start.tv_sec < 24 * 3600) {
+ if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
(void)strftime(buf, sizeof(buf) - 1, "%l:%M%p", tp);
- } else if (now - k->ki_u.u_start.tv_sec < 7 * 86400) {
+ } else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
(void)strftime(buf, sizeof(buf) - 1, "%a%I%p", tp);
} else
(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
@@ -384,11 +382,11 @@ lstarted(k, ve)
char buf[100];
v = ve->var;
- if (!k->ki_u.u_valid) {
+ if (!k->ki_valid) {
(void)printf("%-*s", v->width, "-");
return;
}
- then = k->ki_u.u_start.tv_sec;
+ then = k->ki_p->ki_start.tv_sec;
(void)strftime(buf, sizeof(buf) -1, "%c", localtime(&then));
(void)printf("%-*s", v->width, buf);
}
@@ -401,10 +399,10 @@ mtxname(k, ve)
VAR *v;
v = ve->var;
- if (KI_PROC(k)->p_blocked) {
- if (KI_PROC(k)->p_mtxname)
+ if (k->ki_p->ki_kiflag & KI_MTXBLOCK) {
+ if (k->ki_p->ki_mtxname[0] != 0)
(void)printf("%-*.*s", v->width, v->width,
- KI_EPROC(k)->e_mtxname);
+ k->ki_p->ki_mtxname);
else
(void)printf("%-*s", v->width, "???");
} else
@@ -419,13 +417,13 @@ wchan(k, ve)
VAR *v;
v = ve->var;
- if (KI_PROC(k)->p_wchan) {
- if (KI_PROC(k)->p_wmesg)
+ if (k->ki_p->ki_wchan) {
+ if (k->ki_p->ki_wmesg[0] != 0)
(void)printf("%-*.*s", v->width, v->width,
- KI_EPROC(k)->e_wmesg);
+ k->ki_p->ki_wmesg);
else
(void)printf("%-*lx", v->width,
- (long)KI_PROC(k)->p_wchan &~ KERNBASE);
+ (long)k->ki_p->ki_wchan &~ KERNBASE);
} else
(void)printf("%-*s", v->width, "-");
}
@@ -443,7 +441,7 @@ vsize(k, ve)
v = ve->var;
(void)printf("%*d", v->width,
- (KI_EPROC(k)->e_vm.vm_map.size/1024));
+ (k->ki_p->ki_size/1024));
}
void
@@ -456,7 +454,7 @@ rssize(k, ve)
v = ve->var;
/* XXX don't have info about shared */
(void)printf("%*lu", v->width,
- (u_long)pgtok(KI_EPROC(k)->e_vm.vm_rssize));
+ (u_long)pgtok(k->ki_p->ki_rssize));
}
void
@@ -467,7 +465,7 @@ p_rssize(k, ve) /* doesn't account for text */
VAR *v;
v = ve->var;
- (void)printf("%*ld", v->width, (long)pgtok(KI_EPROC(k)->e_vm.vm_rssize));
+ (void)printf("%*ld", v->width, (long)pgtok(k->ki_p->ki_rssize));
}
void
@@ -481,7 +479,7 @@ cputime(k, ve)
char obuff[128];
v = ve->var;
- if (KI_PROC(k)->p_stat == SZOMB || !k->ki_u.u_valid) {
+ if (k->ki_p->ki_stat == SZOMB || !k->ki_valid) {
secs = 0;
psecs = 0;
} else {
@@ -490,13 +488,11 @@ cputime(k, 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_runtime / 1000000;
- psecs = KI_PROC(k)->p_runtime % 1000000;
+ secs = k->ki_p->ki_runtime / 1000000;
+ psecs = k->ki_p->ki_runtime % 1000000;
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 += k->ki_p->ki_childtime.tv_sec;
+ psecs += k->ki_p->ki_childtime.tv_usec;
}
/*
* round and scale to 100's
@@ -514,7 +510,6 @@ double
getpcpu(k)
KINFO *k;
{
- struct proc *p;
static int failure;
if (!nlistread)
@@ -522,16 +517,15 @@ getpcpu(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 (k->ki_p->ki_swtime == 0 || (k->ki_p->ki_flag & P_INMEM) == 0)
return (0.0);
if (rawcpu)
- return (100.0 * fxtofl(p->p_pctcpu));
- return (100.0 * fxtofl(p->p_pctcpu) /
- (1.0 - exp(p->p_swtime * log(fxtofl(ccpu)))));
+ return (100.0 * fxtofl(k->ki_p->ki_pctcpu));
+ return (100.0 * fxtofl(k->ki_p->ki_pctcpu) /
+ (1.0 - exp(k->ki_p->ki_swtime * log(fxtofl(ccpu)))));
}
void
@@ -550,8 +544,6 @@ getpmem(k)
KINFO *k;
{
static int failure;
- struct proc *p;
- struct eproc *e;
double fracmem;
int szptudot;
@@ -560,14 +552,12 @@ getpmem(k)
if (failure)
return (0.0);
- p = KI_PROC(k);
- e = KI_EPROC(k);
- if ((p->p_flag & P_INMEM) == 0)
+ if ((k->ki_p->ki_flag & P_INMEM) == 0)
return (0.0);
/* XXX want pmap ptpages, segtab, etc. (per architecture) */
szptudot = UPAGES;
/* XXX don't have info about shared */
- fracmem = ((float)e->e_vm.vm_rssize + szptudot)/mempages;
+ fracmem = ((float)k->ki_p->ki_rssize + szptudot)/mempages;
return (100.0 * fracmem);
}
@@ -591,7 +581,7 @@ pagein(k, ve)
v = ve->var;
(void)printf("%*ld", v->width,
- k->ki_u.u_valid ? k->ki_u.u_ru.ru_majflt : 0);
+ k->ki_valid ? k->ki_p->ki_rusage.ru_majflt : 0);
}
void
@@ -614,7 +604,7 @@ tsize(k, ve)
VAR *v;
v = ve->var;
- (void)printf("%*ld", v->width, (long)pgtok(KI_EPROC(k)->e_vm.vm_tsize));
+ (void)printf("%*ld", v->width, (long)pgtok(k->ki_p->ki_tsize));
}
void
@@ -628,7 +618,7 @@ rtprior(k, ve)
unsigned prio, type;
v = ve->var;
- prtp = (struct rtprio *) ((char *)KI_PROC(k) + v->off);
+ prtp = (struct rtprio *) ((char *)k + v->off);
prio = prtp->prio;
type = prtp->type;
switch (type) {
@@ -702,39 +692,14 @@ printval(bp, v)
}
void
-pvar(k, ve)
+kvar(k, ve)
KINFO *k;
VARENT *ve;
{
VAR *v;
v = ve->var;
- printval((char *)((char *)KI_PROC(k) + v->off), v);
-}
-
-void
-evar(k, ve)
- KINFO *k;
- VARENT *ve;
-{
- VAR *v;
-
- v = ve->var;
- printval((char *)((char *)KI_EPROC(k) + v->off), v);
-}
-
-void
-uvar(k, ve)
- KINFO *k;
- VARENT *ve;
-{
- VAR *v;
-
- v = ve->var;
- if (k->ki_u.u_valid)
- printval((char *)((char *)&k->ki_u + v->off), v);
- else
- (void)printf("%*s", v->width, "-");
+ printval((char *)((char *)k->ki_p + v->off), v);
}
void
@@ -745,8 +710,8 @@ rvar(k, ve)
VAR *v;
v = ve->var;
- if (k->ki_u.u_valid)
- printval((char *)((char *)(&k->ki_u.u_ru) + v->off), v);
+ if (k->ki_valid)
+ printval((char *)((char *)(&k->ki_p->ki_rusage) + v->off), v);
else
(void)printf("%*s", v->width, "-");
}
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 9f513b2..f919383 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -368,13 +368,12 @@ main(argc, argv)
* for each proc, call each variable output function.
*/
for (i = lineno = 0; i < nentries; i++) {
- if (xflg == 0 && (KI_EPROC(&kinfo[i])->e_tdev == NODEV ||
- (KI_PROC(&kinfo[i])->p_flag & P_CONTROLT ) == 0))
+ if (xflg == 0 && ((&kinfo[i])->ki_p->ki_tdev == NODEV ||
+ ((&kinfo[i])->ki_p->ki_flag & P_CONTROLT ) == 0))
continue;
if (nuids > 1) {
for (uid = 0; uid < nuids; uid++)
- if (KI_EPROC(&kinfo[i])->e_ucred.cr_uid ==
- uids[uid])
+ if ((&kinfo[i])->ki_p->ki_uid == uids[uid])
break;
if (uid == nuids)
continue;
@@ -509,38 +508,32 @@ fmt(fn, ki, comm, maxlen)
return (s);
}
-#define UREADOK(ki) (forceuread || (KI_PROC(ki)->p_flag & P_INMEM))
+#define UREADOK(ki) (forceuread || (ki->ki_p->ki_flag & P_INMEM))
static void
saveuser(ki)
KINFO *ki;
{
- struct usave *usp;
- usp = &ki->ki_u;
-
- if (KI_PROC(ki)->p_flag & P_INMEM) {
+ if (ki->ki_p->ki_flag & P_INMEM) {
/*
* The u-area might be swapped out, and we can't get
* at it because we have a crashdump and no swap.
* If it's here fill in these fields, otherwise, just
* leave them 0.
*/
- usp->u_start = KI_EPROC(ki)->e_stats.p_start;
- usp->u_ru = KI_EPROC(ki)->e_stats.p_ru;
- usp->u_cru = KI_EPROC(ki)->e_stats.p_cru;
- usp->u_valid = 1;
+ ki->ki_valid = 1;
} else
- usp->u_valid = 0;
+ ki->ki_valid = 0;
/*
* save arguments if needed
*/
- if (needcomm && (UREADOK(ki) || (KI_PROC(ki)->p_args != NULL))) {
- ki->ki_args = fmt(kvm_getargv, ki, KI_PROC(ki)->p_comm,
+ if (needcomm && (UREADOK(ki) || (ki->ki_p->ki_args != NULL))) {
+ ki->ki_args = fmt(kvm_getargv, ki, ki->ki_p->ki_comm,
MAXCOMLEN);
} else if (needcomm) {
- ki->ki_args = malloc(strlen(KI_PROC(ki)->p_comm) + 3);
- sprintf(ki->ki_args, "(%s)", KI_PROC(ki)->p_comm);
+ ki->ki_args = malloc(strlen(ki->ki_p->ki_comm) + 3);
+ sprintf(ki->ki_args, "(%s)", ki->ki_p->ki_comm);
} else {
ki->ki_args = NULL;
}
@@ -559,16 +552,16 @@ pscomp(a, b)
const void *a, *b;
{
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 VSIZE(k) ((k)->ki_p->ki_dsize + (k)->ki_p->ki_ssize + \
+ (k)->ki_p->ki_tsize)
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;
+ i = ((KINFO *)a)->ki_p->ki_tdev - ((KINFO *)b)->ki_p->ki_tdev;
if (i == 0)
- i = KI_PROC((KINFO *)a)->p_pid - KI_PROC((KINFO *)b)->p_pid;
+ i = ((KINFO *)a)->ki_p->ki_pid - ((KINFO *)b)->ki_p->ki_pid;
return (i);
}
diff --git a/bin/ps/ps.h b/bin/ps/ps.h
index f8d244c..c7769eb 100644
--- a/bin/ps/ps.h
+++ b/bin/ps/ps.h
@@ -37,22 +37,11 @@
#define UNLIMITED 0 /* unlimited terminal width */
enum type { CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR };
-struct usave {
- struct timeval u_start;
- struct rusage u_ru;
- struct rusage u_cru;
- char u_acflag;
- 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 */
+ struct kinfo_proc *ki_p; /* kinfo_proc structure */
char *ki_args; /* exec args */
char *ki_env; /* environment */
+ int ki_valid; /* 1 => uarea stuff valid */
} KINFO;
/* Variables. */
@@ -77,8 +66,8 @@ typedef struct var {
short width; /* printing width */
/*
* The following (optional) elements are hooks for passing information
- * to the generic output routines: pvar, evar, uvar (those which print
- * simple elements from well known structures: proc, eproc, usave)
+ * to the generic output routine pvar (which prints simple elements
+ * from the well known kinfo_proc structure).
*/
int off; /* offset in structure */
enum type type; /* type of element */
OpenPOWER on IntegriCloud