Home | History | Annotate | Line # | Download | only in ps
print.c revision 1.21
      1 /*	$NetBSD: print.c,v 1.21 1995/05/18 20:33:24 mycroft Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1990, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #ifndef lint
     37 #if 0
     38 static char sccsid[] = "@(#)print.c	8.6 (Berkeley) 4/16/94";
     39 #else
     40 static char rcsid[] = "$NetBSD: print.c,v 1.21 1995/05/18 20:33:24 mycroft Exp $";
     41 #endif
     42 #endif /* not lint */
     43 
     44 #include <sys/param.h>
     45 #include <sys/time.h>
     46 #include <sys/resource.h>
     47 #include <sys/proc.h>
     48 #include <sys/stat.h>
     49 
     50 #ifdef P_PPWAIT
     51 #define NEWVM
     52 #endif
     53 
     54 #ifdef NEWVM
     55 #include <sys/ucred.h>
     56 #include <sys/sysctl.h>
     57 #include <vm/vm.h>
     58 #else
     59 #include <machine/pte.h>
     60 #include <sys/vmparam.h>
     61 #include <sys/vm.h>
     62 #endif
     63 
     64 #include <err.h>
     65 #include <kvm.h>
     66 #include <math.h>
     67 #include <nlist.h>
     68 #include <stddef.h>
     69 #include <stdio.h>
     70 #include <stdlib.h>
     71 #include <string.h>
     72 #include <vis.h>
     73 #include <tzfile.h>
     74 #include <unistd.h>
     75 
     76 #include "ps.h"
     77 
     78 extern kvm_t *kd;
     79 extern int needenv, needcomm, commandonly;
     80 
     81 static char *cmdpart __P((char *));
     82 static void fmt_puts __P((char *, int *));
     83 static void fmt_putc __P((int, int *));
     84 
     85 static char *
     86 cmdpart(arg0)
     87 	char *arg0;
     88 {
     89 	char *cp;
     90 
     91 	return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
     92 }
     93 
     94 void
     95 printheader()
     96 {
     97 	VAR *v;
     98 	struct varent *vent;
     99 
    100 	for (vent = vhead; vent; vent = vent->next) {
    101 		v = vent->var;
    102 		if (v->flag & LJUST) {
    103 			if (vent->next == NULL)	/* last one */
    104 				(void)printf("%s", v->header);
    105 			else
    106 				(void)printf("%-*s", v->width, v->header);
    107 		} else
    108 			(void)printf("%*s", v->width, v->header);
    109 		if (vent->next != NULL)
    110 			(void)putchar(' ');
    111 	}
    112 	(void)putchar('\n');
    113 }
    114 
    115 static void
    116 fmt_puts(s, leftp)
    117 	char *s;
    118 	int *leftp;
    119 {
    120 	static char *v = 0, *nv;
    121 	static int maxlen = 0;
    122 	int len;
    123 
    124 	if (*leftp == 0)
    125 		return;
    126 	len = strlen(s) * 4 + 1;
    127 	if (len > maxlen) {
    128 		if (maxlen == 0)
    129 			maxlen = getpagesize();
    130 		while (len > maxlen)
    131 			maxlen *= 2;
    132 		nv = realloc(v, maxlen);
    133 		if (nv == 0)
    134 			return;
    135 		v = nv;
    136 	}
    137 	strvis(v, s, VIS_TAB | VIS_NL | VIS_CSTYLE);
    138 	if (*leftp != -1) {
    139 		len = strlen(v);
    140 		if (len > *leftp) {
    141 			printf("%.*s", *leftp, v);
    142 			*leftp = 0;
    143 		} else {
    144 			printf("%s", v);
    145 			*leftp -= len;
    146 		}
    147 	} else
    148 		printf("%s", v);
    149 }
    150 
    151 static void
    152 fmt_putc(c, leftp)
    153 	int c;
    154 	int *leftp;
    155 {
    156 
    157 	if (*leftp == 0)
    158 		return;
    159 	if (*leftp != -1)
    160 		*leftp -= 1;
    161 	putchar(c);
    162 }
    163 
    164 void
    165 command(ki, ve)
    166 	KINFO *ki;
    167 	VARENT *ve;
    168 {
    169 	VAR *v;
    170 	int left;
    171 	char **argv, **p;
    172 
    173 	v = ve->var;
    174 	if (ve->next != NULL || termwidth != UNLIMITED) {
    175 		if (ve->next == NULL) {
    176 			left = termwidth - (totwidth - v->width);
    177 			if (left < 1) /* already wrapped, just use std width */
    178 				left = v->width;
    179 		} else
    180 			left = v->width;
    181 	} else
    182 		left = -1;
    183 	if (needenv) {
    184 		argv = kvm_getenvv(kd, ki->ki_p, termwidth);
    185 		if (p = argv) {
    186 			while (*p) {
    187 				fmt_puts(*p, &left);
    188 				p++;
    189 				fmt_putc(' ', &left);
    190 			}
    191 		}
    192 	}
    193 	if (needcomm) {
    194 		if (!commandonly) {
    195 			argv = kvm_getargv(kd, ki->ki_p, termwidth);
    196 			if (p = argv) {
    197 				while (*p) {
    198 					fmt_puts(*p, &left);
    199 					p++;
    200 					fmt_putc(' ', &left);
    201 				}
    202 			}
    203 			if (argv == 0 || argv[0] == 0 ||
    204 			    strcmp(cmdpart(argv[0]), KI_PROC(ki)->p_comm)) {
    205 				fmt_putc('(', &left);
    206 				fmt_puts(KI_PROC(ki)->p_comm, &left);
    207 				fmt_putc(')', &left);
    208 			}
    209 		} else {
    210 			fmt_puts(KI_PROC(ki)->p_comm, &left);
    211 		}
    212 	}
    213 }
    214 
    215 void
    216 ucomm(k, ve)
    217 	KINFO *k;
    218 	VARENT *ve;
    219 {
    220 	VAR *v;
    221 
    222 	v = ve->var;
    223 	(void)printf("%-*s", v->width, KI_PROC(k)->p_comm);
    224 }
    225 
    226 void
    227 logname(k, ve)
    228 	KINFO *k;
    229 	VARENT *ve;
    230 {
    231 	VAR *v;
    232 
    233 	v = ve->var;
    234 #ifndef NEWVM
    235 	(void)printf("%-*s", v->width, KI_PROC(k)->p_logname);
    236 #else
    237 	(void)printf("%-*s", v->width, KI_EPROC(k)->e_login);
    238 #endif
    239 }
    240 
    241 void
    242 state(k, ve)
    243 	KINFO *k;
    244 	VARENT *ve;
    245 {
    246 	struct proc *p;
    247 	int flag;
    248 	char *cp;
    249 	VAR *v;
    250 	char buf[16];
    251 
    252 	v = ve->var;
    253 	p = KI_PROC(k);
    254 	flag = p->p_flag;
    255 	cp = buf;
    256 
    257 	switch (p->p_stat) {
    258 
    259 	case SSTOP:
    260 		*cp = 'T';
    261 		break;
    262 
    263 	case SSLEEP:
    264 		if (flag & P_SINTR)	/* interuptable (long) */
    265 			*cp = p->p_slptime >= MAXSLP ? 'I' : 'S';
    266 		else
    267 			*cp = 'D';
    268 		break;
    269 
    270 	case SRUN:
    271 	case SIDL:
    272 		*cp = 'R';
    273 		break;
    274 
    275 	case SZOMB:
    276 		*cp = 'Z';
    277 		break;
    278 
    279 	default:
    280 		*cp = '?';
    281 	}
    282 	cp++;
    283 	if (flag & P_INMEM) {
    284 #ifndef NEWVM
    285 		if (p->p_rssize > p->p_maxrss)
    286 			*cp++ = '>';
    287 #endif
    288 	} else
    289 		*cp++ = 'W';
    290 	if (p->p_nice < NZERO)
    291 		*cp++ = '<';
    292 	else if (p->p_nice > NZERO)
    293 		*cp++ = 'N';
    294 #ifndef NEWVM
    295 	if (flag & SUANOM)
    296 		*cp++ = 'A';
    297 	else if (flag & SSEQL)
    298 		*cp++ = 'S';
    299 #endif
    300 	if (flag & P_TRACED)
    301 		*cp++ = 'X';
    302 	if (flag & P_WEXIT && p->p_stat != SZOMB)
    303 		*cp++ = 'E';
    304 #ifdef NEWVM
    305 	if (flag & P_PPWAIT)
    306 #else
    307 	if (flag & SVFORK)
    308 #endif
    309 		*cp++ = 'V';
    310 #ifdef NEWVM
    311 	if ((flag & P_SYSTEM) || p->p_holdcnt)
    312 #else
    313 	if (flag & (SSYS|SLOCK|SULOCK|SKEEP|SPHYSIO))
    314 #endif
    315 		*cp++ = 'L';
    316 	if (KI_EPROC(k)->e_flag & EPROC_SLEADER)
    317 		*cp++ = 's';
    318 	if ((flag & P_CONTROLT) && KI_EPROC(k)->e_pgid == KI_EPROC(k)->e_tpgid)
    319 		*cp++ = '+';
    320 	*cp = '\0';
    321 	(void)printf("%-*s", v->width, buf);
    322 }
    323 
    324 void
    325 pri(k, ve)
    326 	KINFO *k;
    327 	VARENT *ve;
    328 {
    329 	VAR *v;
    330 
    331 	v = ve->var;
    332 	(void)printf("%*d", v->width, KI_PROC(k)->p_priority - PZERO);
    333 }
    334 
    335 void
    336 uname(k, ve)
    337 	KINFO *k;
    338 	VARENT *ve;
    339 {
    340 	VAR *v;
    341 
    342 	v = ve->var;
    343 #ifndef NEWVM
    344 	(void)printf("%-*s",
    345 	    (int)v->width, user_from_uid(KI_PROC(k)->p_uid, 0));
    346 #else
    347 	(void)printf("%-*s",
    348 	    (int)v->width, user_from_uid(KI_EPROC(k)->e_ucred.cr_uid, 0));
    349 #endif
    350 }
    351 
    352 void
    353 runame(k, ve)
    354 	KINFO *k;
    355 	VARENT *ve;
    356 {
    357 	VAR *v;
    358 
    359 	v = ve->var;
    360 #ifndef NEWVM
    361 	(void)printf("%-*s",
    362 	    (int)v->width, user_from_uid(KI_PROC(k)->p_ruid, 0));
    363 #else
    364 	(void)printf("%-*s",
    365 	    (int)v->width, user_from_uid(KI_EPROC(k)->e_pcred.p_ruid, 0));
    366 #endif
    367 }
    368 
    369 void
    370 tdev(k, ve)
    371 	KINFO *k;
    372 	VARENT *ve;
    373 {
    374 	VAR *v;
    375 	dev_t dev;
    376 	char buff[16];
    377 
    378 	v = ve->var;
    379 	dev = KI_EPROC(k)->e_tdev;
    380 	if (dev == NODEV)
    381 		(void)printf("%*s", v->width, "??");
    382 	else {
    383 		(void)snprintf(buff, sizeof(buff),
    384 		    "%d/%d", major(dev), minor(dev));
    385 		(void)printf("%*s", v->width, buff);
    386 	}
    387 }
    388 
    389 void
    390 tname(k, ve)
    391 	KINFO *k;
    392 	VARENT *ve;
    393 {
    394 	VAR *v;
    395 	dev_t dev;
    396 	char *ttname;
    397 
    398 	v = ve->var;
    399 	dev = KI_EPROC(k)->e_tdev;
    400 	if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
    401 		(void)printf("%-*s", v->width, "??");
    402 	else {
    403 		if (strncmp(ttname, "tty", 3) == 0)
    404 			ttname += 3;
    405 		(void)printf("%*.*s%c", v->width-1, v->width-1, ttname,
    406 			KI_EPROC(k)->e_flag & EPROC_CTTY ? ' ' : '-');
    407 	}
    408 }
    409 
    410 void
    411 longtname(k, ve)
    412 	KINFO *k;
    413 	VARENT *ve;
    414 {
    415 	VAR *v;
    416 	dev_t dev;
    417 	char *ttname;
    418 
    419 	v = ve->var;
    420 	dev = KI_EPROC(k)->e_tdev;
    421 	if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
    422 		(void)printf("%-*s", v->width, "??");
    423 	else
    424 		(void)printf("%-*s", v->width, ttname);
    425 }
    426 
    427 void
    428 started(k, ve)
    429 	KINFO *k;
    430 	VARENT *ve;
    431 {
    432 	VAR *v;
    433 	static time_t now;
    434 	struct tm *tp;
    435 	char buf[100];
    436 
    437 	v = ve->var;
    438 	if (!k->ki_u.u_valid) {
    439 		(void)printf("%-*s", v->width, "-");
    440 		return;
    441 	}
    442 
    443 	tp = localtime(&k->ki_u.u_start.tv_sec);
    444 	if (!now)
    445 		(void)time(&now);
    446 	if (now - k->ki_u.u_start.tv_sec < 24 * SECSPERHOUR) {
    447 		/* I *hate* SCCS... */
    448 		static char fmt[] = __CONCAT("%l:%", "M%p");
    449 		(void)strftime(buf, sizeof(buf) - 1, fmt, tp);
    450 	} else if (now - k->ki_u.u_start.tv_sec < 7 * SECSPERDAY) {
    451 		/* I *hate* SCCS... */
    452 		static char fmt[] = __CONCAT("%a%", "I%p");
    453 		(void)strftime(buf, sizeof(buf) - 1, fmt, tp);
    454 	} else
    455 		(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
    456 	(void)printf("%-*s", v->width, buf);
    457 }
    458 
    459 void
    460 lstarted(k, ve)
    461 	KINFO *k;
    462 	VARENT *ve;
    463 {
    464 	VAR *v;
    465 	char buf[100];
    466 
    467 	v = ve->var;
    468 	if (!k->ki_u.u_valid) {
    469 		(void)printf("%-*s", v->width, "-");
    470 		return;
    471 	}
    472 	(void)strftime(buf, sizeof(buf) -1, "%C",
    473 	    localtime(&k->ki_u.u_start.tv_sec));
    474 	(void)printf("%-*s", v->width, buf);
    475 }
    476 
    477 void
    478 wchan(k, ve)
    479 	KINFO *k;
    480 	VARENT *ve;
    481 {
    482 	VAR *v;
    483 
    484 	v = ve->var;
    485 	if (KI_PROC(k)->p_wchan) {
    486 		if (KI_PROC(k)->p_wmesg)
    487 			(void)printf("%-*.*s", v->width, v->width,
    488 				      KI_EPROC(k)->e_wmesg);
    489 		else
    490 			(void)printf("%-*lx", v->width,
    491 			    (long)KI_PROC(k)->p_wchan &~ KERNBASE);
    492 	} else
    493 		(void)printf("%-*s", v->width, "-");
    494 }
    495 
    496 #define pgtok(a)        (((a)*getpagesize())/1024)
    497 
    498 void
    499 vsize(k, ve)
    500 	KINFO *k;
    501 	VARENT *ve;
    502 {
    503 	VAR *v;
    504 
    505 	v = ve->var;
    506 	(void)printf("%*d", v->width,
    507 #ifndef NEWVM
    508 	    pgtok(KI_PROC(k)->p_dsize +
    509 	        KI_PROC(k)->p_ssize + KI_EPROC(k)->e_xsize));
    510 #else
    511 	    pgtok(KI_EPROC(k)->e_vm.vm_dsize + KI_EPROC(k)->e_vm.vm_ssize +
    512 		KI_EPROC(k)->e_vm.vm_tsize));
    513 #endif
    514 }
    515 
    516 void
    517 rssize(k, ve)
    518 	KINFO *k;
    519 	VARENT *ve;
    520 {
    521 	VAR *v;
    522 
    523 	v = ve->var;
    524 #ifndef NEWVM
    525 	(void)printf("%*d", v->width,
    526 	    pgtok(KI_PROC(k)->p_rssize + (KI_EPROC(k)->e_xccount ?
    527 	    (KI_EPROC(k)->e_xrssize / KI_EPROC(k)->e_xccount) : 0)));
    528 #else
    529 	/* XXX don't have info about shared */
    530 	(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_rssize));
    531 #endif
    532 }
    533 
    534 void
    535 p_rssize(k, ve)		/* doesn't account for text */
    536 	KINFO *k;
    537 	VARENT *ve;
    538 {
    539 	VAR *v;
    540 
    541 	v = ve->var;
    542 #ifndef NEWVM
    543 	(void)printf("%*d", v->width, pgtok(KI_PROC(k)->p_rssize));
    544 #else
    545 	(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_rssize));
    546 #endif
    547 }
    548 
    549 void
    550 cputime(k, ve)
    551 	KINFO *k;
    552 	VARENT *ve;
    553 {
    554 	VAR *v;
    555 	long secs;
    556 	long psecs;	/* "parts" of a second. first micro, then centi */
    557 	char obuff[128];
    558 
    559 	v = ve->var;
    560 	if (KI_PROC(k)->p_stat == SZOMB || !k->ki_u.u_valid) {
    561 		secs = 0;
    562 		psecs = 0;
    563 	} else {
    564 		/*
    565 		 * This counts time spent handling interrupts.  We could
    566 		 * fix this, but it is not 100% trivial (and interrupt
    567 		 * time fractions only work on the sparc anyway).	XXX
    568 		 */
    569 		secs = KI_PROC(k)->p_rtime.tv_sec;
    570 		psecs = KI_PROC(k)->p_rtime.tv_usec;
    571 		if (sumrusage) {
    572 			secs += k->ki_u.u_cru.ru_utime.tv_sec +
    573 				k->ki_u.u_cru.ru_stime.tv_sec;
    574 			psecs += k->ki_u.u_cru.ru_utime.tv_usec +
    575 				k->ki_u.u_cru.ru_stime.tv_usec;
    576 		}
    577 		/*
    578 		 * round and scale to 100's
    579 		 */
    580 		psecs = (psecs + 5000) / 10000;
    581 		secs += psecs / 100;
    582 		psecs = psecs % 100;
    583 	}
    584 	(void)snprintf(obuff, sizeof(obuff),
    585 	    "%3ld:%02ld.%02ld", secs/60, secs%60, psecs);
    586 	(void)printf("%*s", v->width, obuff);
    587 }
    588 
    589 double
    590 getpcpu(k)
    591 	KINFO *k;
    592 {
    593 	struct proc *p;
    594 	static int failure;
    595 
    596 	if (!nlistread)
    597 		failure = donlist();
    598 	if (failure)
    599 		return (0.0);
    600 
    601 	p = KI_PROC(k);
    602 #define	fxtofl(fixpt)	((double)(fixpt) / fscale)
    603 
    604 	/* XXX - I don't like this */
    605 	if (p->p_swtime == 0 || (p->p_flag & P_INMEM) == 0)
    606 		return (0.0);
    607 	if (rawcpu)
    608 		return (100.0 * fxtofl(p->p_pctcpu));
    609 	return (100.0 * fxtofl(p->p_pctcpu) /
    610 		(1.0 - exp(p->p_swtime * log(fxtofl(ccpu)))));
    611 }
    612 
    613 void
    614 pcpu(k, ve)
    615 	KINFO *k;
    616 	VARENT *ve;
    617 {
    618 	VAR *v;
    619 
    620 	v = ve->var;
    621 	(void)printf("%*.1f", v->width, getpcpu(k));
    622 }
    623 
    624 double
    625 getpmem(k)
    626 	KINFO *k;
    627 {
    628 	static int failure;
    629 	struct proc *p;
    630 	struct eproc *e;
    631 	double fracmem;
    632 	int szptudot;
    633 
    634 	if (!nlistread)
    635 		failure = donlist();
    636 	if (failure)
    637 		return (0.0);
    638 
    639 	p = KI_PROC(k);
    640 	e = KI_EPROC(k);
    641 	if ((p->p_flag & P_INMEM) == 0)
    642 		return (0.0);
    643 #ifndef NEWVM
    644 	szptudot = USPACE/getpagesize() +
    645 	    clrnd(ctopt(p->p_dsize + p->p_ssize + e->e_xsize));
    646 	fracmem = ((float)p->p_rssize + szptudot)/CLSIZE/mempages;
    647 	if (p->p_textp && e->e_xccount)
    648 		fracmem += ((float)e->e_xrssize)/CLSIZE/e->e_xccount/mempages;
    649 #else
    650 	/* XXX want pmap ptpages, segtab, etc. (per architecture) */
    651 	szptudot = USPACE/getpagesize();
    652 	/* XXX don't have info about shared */
    653 	fracmem = ((float)e->e_vm.vm_rssize + szptudot)/CLSIZE/mempages;
    654 #endif
    655 	return (100.0 * fracmem);
    656 }
    657 
    658 void
    659 pmem(k, ve)
    660 	KINFO *k;
    661 	VARENT *ve;
    662 {
    663 	VAR *v;
    664 
    665 	v = ve->var;
    666 	(void)printf("%*.1f", v->width, getpmem(k));
    667 }
    668 
    669 void
    670 pagein(k, ve)
    671 	KINFO *k;
    672 	VARENT *ve;
    673 {
    674 	VAR *v;
    675 
    676 	v = ve->var;
    677 	(void)printf("%*d", v->width,
    678 	    k->ki_u.u_valid ? k->ki_u.u_ru.ru_majflt : 0);
    679 }
    680 
    681 void
    682 maxrss(k, ve)
    683 	KINFO *k;
    684 	VARENT *ve;
    685 {
    686 	VAR *v;
    687 
    688 	v = ve->var;
    689 #ifndef NEWVM	/* not yet */
    690 	if (KI_PROC(k)->p_maxrss != (RLIM_INFINITY/getpagesize()))
    691 		(void)printf("%*d", v->width, pgtok(KI_PROC(k)->p_maxrss));
    692 	else
    693 #endif
    694 		(void)printf("%*s", v->width, "-");
    695 }
    696 
    697 void
    698 tsize(k, ve)
    699 	KINFO *k;
    700 	VARENT *ve;
    701 {
    702 	VAR *v;
    703 
    704 	v = ve->var;
    705 #ifndef NEWVM
    706 	(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_xsize));
    707 #else
    708 	(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_vm.vm_tsize));
    709 #endif
    710 }
    711 
    712 #ifndef NEWVM
    713 void
    714 trss(k, ve)
    715 	KINFO *k;
    716 	VARENT *ve;
    717 {
    718 	VAR *v;
    719 
    720 	v = ve->var;
    721 	(void)printf("%*d", v->width, pgtok(KI_EPROC(k)->e_xrssize));
    722 }
    723 #endif
    724 
    725 /*
    726  * Generic output routines.  Print fields from various prototype
    727  * structures.
    728  */
    729 static void
    730 printval(bp, v)
    731 	char *bp;
    732 	VAR *v;
    733 {
    734 	static char ofmt[32] = "%";
    735 	char *fcp, *cp;
    736 
    737 	cp = ofmt + 1;
    738 	fcp = v->fmt;
    739 	if (v->flag & LJUST)
    740 		*cp++ = '-';
    741 	*cp++ = '*';
    742 	while (*cp++ = *fcp++);
    743 
    744 	switch (v->type) {
    745 	case CHAR:
    746 		(void)printf(ofmt, v->width, *(char *)bp);
    747 		break;
    748 	case UCHAR:
    749 		(void)printf(ofmt, v->width, *(u_char *)bp);
    750 		break;
    751 	case SHORT:
    752 		(void)printf(ofmt, v->width, *(short *)bp);
    753 		break;
    754 	case USHORT:
    755 		(void)printf(ofmt, v->width, *(u_short *)bp);
    756 		break;
    757 	case INT:
    758 		(void)printf(ofmt, v->width, *(int *)bp);
    759 		break;
    760 	case UINT:
    761 		(void)printf(ofmt, v->width, *(u_int *)bp);
    762 		break;
    763 	case LONG:
    764 		(void)printf(ofmt, v->width, *(long *)bp);
    765 		break;
    766 	case ULONG:
    767 		(void)printf(ofmt, v->width, *(u_long *)bp);
    768 		break;
    769 	case KPTR:
    770 		(void)printf(ofmt, v->width, *(u_long *)bp &~ KERNBASE);
    771 		break;
    772 	default:
    773 		errx(1, "unknown type %d", v->type);
    774 	}
    775 }
    776 
    777 void
    778 pvar(k, ve)
    779 	KINFO *k;
    780 	VARENT *ve;
    781 {
    782 	VAR *v;
    783 
    784 	v = ve->var;
    785 	printval((char *)((char *)KI_PROC(k) + v->off), v);
    786 }
    787 
    788 void
    789 evar(k, ve)
    790 	KINFO *k;
    791 	VARENT *ve;
    792 {
    793 	VAR *v;
    794 
    795 	v = ve->var;
    796 	printval((char *)((char *)KI_EPROC(k) + v->off), v);
    797 }
    798 
    799 void
    800 uvar(k, ve)
    801 	KINFO *k;
    802 	VARENT *ve;
    803 {
    804 	VAR *v;
    805 
    806 	v = ve->var;
    807 	if (k->ki_u.u_valid)
    808 		printval((char *)((char *)&k->ki_u + v->off), v);
    809 	else
    810 		(void)printf("%*s", v->width, "-");
    811 }
    812 
    813 void
    814 rvar(k, ve)
    815 	KINFO *k;
    816 	VARENT *ve;
    817 {
    818 	VAR *v;
    819 
    820 	v = ve->var;
    821 	if (k->ki_u.u_valid)
    822 		printval((char *)((char *)(&k->ki_u.u_ru) + v->off), v);
    823 	else
    824 		(void)printf("%*s", v->width, "-");
    825 }
    826