xref: /freebsd/bin/ps/print.c (revision 76e1a9fe48b8202078fa822ea267bf03f1f7db1b)
14b88c807SRodney W. Grimes /*-
24b88c807SRodney W. Grimes  * Copyright (c) 1990, 1993, 1994
34b88c807SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
44b88c807SRodney W. Grimes  *
54b88c807SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
64b88c807SRodney W. Grimes  * modification, are permitted provided that the following conditions
74b88c807SRodney W. Grimes  * are met:
84b88c807SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
94b88c807SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
104b88c807SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
114b88c807SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
124b88c807SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
134b88c807SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
144b88c807SRodney W. Grimes  *    must display the following acknowledgement:
154b88c807SRodney W. Grimes  *	This product includes software developed by the University of
164b88c807SRodney W. Grimes  *	California, Berkeley and its contributors.
174b88c807SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
184b88c807SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
194b88c807SRodney W. Grimes  *    without specific prior written permission.
204b88c807SRodney W. Grimes  *
214b88c807SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
224b88c807SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
234b88c807SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
244b88c807SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
254b88c807SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
264b88c807SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
274b88c807SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
284b88c807SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
294b88c807SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
304b88c807SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
314b88c807SRodney W. Grimes  * SUCH DAMAGE.
324b88c807SRodney W. Grimes  */
334b88c807SRodney W. Grimes 
34871e8d8cSMark Murray #include <sys/cdefs.h>
35871e8d8cSMark Murray 
36871e8d8cSMark Murray __FBSDID("$FreeBSD$");
37871e8d8cSMark Murray 
38c9a8d1f4SPhilippe Charnier #if 0
39871e8d8cSMark Murray #ifndef lint
40c9a8d1f4SPhilippe Charnier static char sccsid[] = "@(#)print.c	8.6 (Berkeley) 4/16/94";
414b88c807SRodney W. Grimes #endif /* not lint */
42871e8d8cSMark Murray #endif
434b88c807SRodney W. Grimes 
444b88c807SRodney W. Grimes #include <sys/param.h>
454b88c807SRodney W. Grimes #include <sys/time.h>
464b88c807SRodney W. Grimes #include <sys/resource.h>
474b88c807SRodney W. Grimes #include <sys/proc.h>
484b88c807SRodney W. Grimes #include <sys/stat.h>
494b88c807SRodney W. Grimes 
508b9b0e39SPoul-Henning Kamp #include <sys/user.h>
514b88c807SRodney W. Grimes #include <sys/sysctl.h>
524b88c807SRodney W. Grimes 
534b88c807SRodney W. Grimes #include <err.h>
54576541a9SWarner Losh #include <grp.h>
55f59105eeSAndrey A. Chernov #include <langinfo.h>
568073a93cSAndrey A. Chernov #include <locale.h>
574b88c807SRodney W. Grimes #include <math.h>
584b88c807SRodney W. Grimes #include <nlist.h>
59576541a9SWarner Losh #include <pwd.h>
604b88c807SRodney W. Grimes #include <stddef.h>
614b88c807SRodney W. Grimes #include <stdio.h>
624b88c807SRodney W. Grimes #include <stdlib.h>
634b88c807SRodney W. Grimes #include <string.h>
64871e8d8cSMark Murray #include <unistd.h>
654b88c807SRodney W. Grimes #include <vis.h>
664b88c807SRodney W. Grimes 
67f1ff35aeSMaxim Sobolev #include "lomac.h"
684b88c807SRodney W. Grimes #include "ps.h"
694b88c807SRodney W. Grimes 
70a3dbc1d8SMark Murray static void printval(char *, VAR *);
71871e8d8cSMark Murray 
724b88c807SRodney W. Grimes void
7346251ddeSWarner Losh printheader(void)
744b88c807SRodney W. Grimes {
754b88c807SRodney W. Grimes 	VAR *v;
764b88c807SRodney W. Grimes 	struct varent *vent;
774b88c807SRodney W. Grimes 
784b88c807SRodney W. Grimes 	for (vent = vhead; vent; vent = vent->next) {
794b88c807SRodney W. Grimes 		v = vent->var;
804b88c807SRodney W. Grimes 		if (v->flag & LJUST) {
814b88c807SRodney W. Grimes 			if (vent->next == NULL)	/* last one */
824b88c807SRodney W. Grimes 				(void)printf("%s", v->header);
834b88c807SRodney W. Grimes 			else
844b88c807SRodney W. Grimes 				(void)printf("%-*s", v->width, v->header);
854b88c807SRodney W. Grimes 		} else
864b88c807SRodney W. Grimes 			(void)printf("%*s", v->width, v->header);
874b88c807SRodney W. Grimes 		if (vent->next != NULL)
884b88c807SRodney W. Grimes 			(void)putchar(' ');
894b88c807SRodney W. Grimes 	}
904b88c807SRodney W. Grimes 	(void)putchar('\n');
914b88c807SRodney W. Grimes }
924b88c807SRodney W. Grimes 
934b88c807SRodney W. Grimes void
9403334017SJuli Mallett arguments(KINFO *k, VARENT *ve)
9503334017SJuli Mallett {
9603334017SJuli Mallett 	VAR *v;
9703334017SJuli Mallett 	int left;
9803334017SJuli Mallett 	char *cp, *vis_args;
9903334017SJuli Mallett 
10003334017SJuli Mallett 	v = ve->var;
10103334017SJuli Mallett 
10203334017SJuli Mallett 	if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
10303334017SJuli Mallett 		errx(1, "malloc failed");
10403334017SJuli Mallett 	strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
10503334017SJuli Mallett 
10603334017SJuli Mallett 	if (ve->next == NULL) {
10703334017SJuli Mallett 		/* last field */
10803334017SJuli Mallett 		if (termwidth == UNLIMITED) {
10903334017SJuli Mallett 			(void)printf("%s", vis_args);
11003334017SJuli Mallett 		} else {
11103334017SJuli Mallett 			left = termwidth - (totwidth - v->width);
11203334017SJuli Mallett 			if (left < 1) /* already wrapped, just use std width */
11303334017SJuli Mallett 				left = v->width;
11403334017SJuli Mallett 			for (cp = vis_args; --left >= 0 && *cp != '\0';)
11503334017SJuli Mallett 				(void)putchar(*cp++);
11603334017SJuli Mallett 		}
11703334017SJuli Mallett 	} else {
11803334017SJuli Mallett 		(void)printf("%-*.*s", v->width, v->width, vis_args);
11903334017SJuli Mallett 	}
12003334017SJuli Mallett 	free(vis_args);
12103334017SJuli Mallett }
12203334017SJuli Mallett 
12303334017SJuli Mallett void
12446251ddeSWarner Losh command(KINFO *k, VARENT *ve)
1254b88c807SRodney W. Grimes {
1264b88c807SRodney W. Grimes 	VAR *v;
1274b88c807SRodney W. Grimes 	int left;
1284b88c807SRodney W. Grimes 	char *cp, *vis_env, *vis_args;
1294b88c807SRodney W. Grimes 
130db91faacSPeter Wemm 	v = ve->var;
131db91faacSPeter Wemm 
132db91faacSPeter Wemm 	if (cflag) {
1333cc273e0SJohn Polstra 		if (ve->next == NULL)	/* last field, don't pad */
1341f7d2501SKirk McKusick 			(void)printf("%s", k->ki_p->ki_comm);
1353cc273e0SJohn Polstra 		else
1361f7d2501SKirk McKusick 			(void)printf("%-*s", v->width, k->ki_p->ki_comm);
137db91faacSPeter Wemm 		return;
138db91faacSPeter Wemm 	}
139db91faacSPeter Wemm 
1404b88c807SRodney W. Grimes 	if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
1414fa7d788SJuli Mallett 		errx(1, "malloc failed");
1424b88c807SRodney W. Grimes 	strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
1434b88c807SRodney W. Grimes 	if (k->ki_env) {
1444b88c807SRodney W. Grimes 		if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1)) == NULL)
1454fa7d788SJuli Mallett 			errx(1, "malloc failed");
1464b88c807SRodney W. Grimes 		strvis(vis_env, k->ki_env, VIS_TAB | VIS_NL | VIS_NOSLASH);
1474b88c807SRodney W. Grimes 	} else
1484b88c807SRodney W. Grimes 		vis_env = NULL;
1494b88c807SRodney W. Grimes 
1504b88c807SRodney W. Grimes 	if (ve->next == NULL) {
1514b88c807SRodney W. Grimes 		/* last field */
1524b88c807SRodney W. Grimes 		if (termwidth == UNLIMITED) {
1534b88c807SRodney W. Grimes 			if (vis_env)
1544b88c807SRodney W. Grimes 				(void)printf("%s ", vis_env);
1554b88c807SRodney W. Grimes 			(void)printf("%s", vis_args);
1564b88c807SRodney W. Grimes 		} else {
1574b88c807SRodney W. Grimes 			left = termwidth - (totwidth - v->width);
1584b88c807SRodney W. Grimes 			if (left < 1) /* already wrapped, just use std width */
1594b88c807SRodney W. Grimes 				left = v->width;
1604b88c807SRodney W. Grimes 			if ((cp = vis_env) != NULL) {
1614b88c807SRodney W. Grimes 				while (--left >= 0 && *cp)
1624b88c807SRodney W. Grimes 					(void)putchar(*cp++);
1634b88c807SRodney W. Grimes 				if (--left >= 0)
1644b88c807SRodney W. Grimes 					putchar(' ');
1654b88c807SRodney W. Grimes 			}
1664b88c807SRodney W. Grimes 			for (cp = vis_args; --left >= 0 && *cp != '\0';)
1674b88c807SRodney W. Grimes 				(void)putchar(*cp++);
1684b88c807SRodney W. Grimes 		}
1694b88c807SRodney W. Grimes 	} else
1704b88c807SRodney W. Grimes 		/* XXX env? */
1714b88c807SRodney W. Grimes 		(void)printf("%-*.*s", v->width, v->width, vis_args);
1724b88c807SRodney W. Grimes 	free(vis_args);
1734b88c807SRodney W. Grimes 	if (vis_env != NULL)
1744b88c807SRodney W. Grimes 		free(vis_env);
1754b88c807SRodney W. Grimes }
1764b88c807SRodney W. Grimes 
1774b88c807SRodney W. Grimes void
17846251ddeSWarner Losh ucomm(KINFO *k, VARENT *ve)
1794b88c807SRodney W. Grimes {
1804b88c807SRodney W. Grimes 	VAR *v;
1814b88c807SRodney W. Grimes 
1824b88c807SRodney W. Grimes 	v = ve->var;
1831f7d2501SKirk McKusick 	(void)printf("%-*s", v->width, k->ki_p->ki_comm);
1844b88c807SRodney W. Grimes }
1854b88c807SRodney W. Grimes 
1864b88c807SRodney W. Grimes void
18746251ddeSWarner Losh logname(KINFO *k, VARENT *ve)
1884b88c807SRodney W. Grimes {
1894b88c807SRodney W. Grimes 	VAR *v;
190ad863cacSSteve Price 	char *s;
1914b88c807SRodney W. Grimes 
1924b88c807SRodney W. Grimes 	v = ve->var;
1931f7d2501SKirk McKusick 	(void)printf("%-*s", v->width, (s = k->ki_p->ki_login, *s) ? s : "-");
1944b88c807SRodney W. Grimes }
1954b88c807SRodney W. Grimes 
1964b88c807SRodney W. Grimes void
19746251ddeSWarner Losh state(KINFO *k, VARENT *ve)
1984b88c807SRodney W. Grimes {
199b40ce416SJulian Elischer 	int flag, sflag, tdflags;
2004b88c807SRodney W. Grimes 	char *cp;
2014b88c807SRodney W. Grimes 	VAR *v;
2024b88c807SRodney W. Grimes 	char buf[16];
2034b88c807SRodney W. Grimes 
2044b88c807SRodney W. Grimes 	v = ve->var;
2051f7d2501SKirk McKusick 	flag = k->ki_p->ki_flag;
206564efb8fSTor Egge 	sflag = k->ki_p->ki_sflag;
207b40ce416SJulian Elischer 	tdflags = k->ki_p->ki_tdflags;	/* XXXKSE */
2084b88c807SRodney W. Grimes 	cp = buf;
2094b88c807SRodney W. Grimes 
2101f7d2501SKirk McKusick 	switch (k->ki_p->ki_stat) {
2114b88c807SRodney W. Grimes 
2124b88c807SRodney W. Grimes 	case SSTOP:
2134b88c807SRodney W. Grimes 		*cp = 'T';
2144b88c807SRodney W. Grimes 		break;
2154b88c807SRodney W. Grimes 
2164b88c807SRodney W. Grimes 	case SSLEEP:
217b40ce416SJulian Elischer 		if (tdflags & TDF_SINTR)	/* interruptable (long) */
2181f7d2501SKirk McKusick 			*cp = k->ki_p->ki_slptime >= MAXSLP ? 'I' : 'S';
2194b88c807SRodney W. Grimes 		else
2204b88c807SRodney W. Grimes 			*cp = 'D';
2214b88c807SRodney W. Grimes 		break;
2224b88c807SRodney W. Grimes 
2234b88c807SRodney W. Grimes 	case SRUN:
2244b88c807SRodney W. Grimes 	case SIDL:
2254b88c807SRodney W. Grimes 		*cp = 'R';
2264b88c807SRodney W. Grimes 		break;
2274b88c807SRodney W. Grimes 
2280384fff8SJason Evans 	case SWAIT:
2290384fff8SJason Evans 		*cp = 'W';
2300384fff8SJason Evans 		break;
2310384fff8SJason Evans 
2320384fff8SJason Evans 	case SMTX:
2330384fff8SJason Evans 		*cp = 'M';
2340384fff8SJason Evans 		break;
2350384fff8SJason Evans 
2364b88c807SRodney W. Grimes 	case SZOMB:
2374b88c807SRodney W. Grimes 		*cp = 'Z';
2384b88c807SRodney W. Grimes 		break;
2394b88c807SRodney W. Grimes 
2404b88c807SRodney W. Grimes 	default:
2414b88c807SRodney W. Grimes 		*cp = '?';
2424b88c807SRodney W. Grimes 	}
2434b88c807SRodney W. Grimes 	cp++;
244e0aa5ab7SJohn Baldwin 	if (!(sflag & PS_INMEM))
2454b88c807SRodney W. Grimes 		*cp++ = 'W';
2461f7d2501SKirk McKusick 	if (k->ki_p->ki_nice < NZERO)
2474b88c807SRodney W. Grimes 		*cp++ = '<';
2481f7d2501SKirk McKusick 	else if (k->ki_p->ki_nice > NZERO)
2494b88c807SRodney W. Grimes 		*cp++ = 'N';
2504b88c807SRodney W. Grimes 	if (flag & P_TRACED)
2514b88c807SRodney W. Grimes 		*cp++ = 'X';
2521f7d2501SKirk McKusick 	if (flag & P_WEXIT && k->ki_p->ki_stat != SZOMB)
2534b88c807SRodney W. Grimes 		*cp++ = 'E';
2544b88c807SRodney W. Grimes 	if (flag & P_PPWAIT)
2554b88c807SRodney W. Grimes 		*cp++ = 'V';
2561f7d2501SKirk McKusick 	if ((flag & P_SYSTEM) || k->ki_p->ki_lock > 0)
2574b88c807SRodney W. Grimes 		*cp++ = 'L';
2581f7d2501SKirk McKusick 	if (k->ki_p->ki_kiflag & KI_SLEADER)
2594b88c807SRodney W. Grimes 		*cp++ = 's';
2601f7d2501SKirk McKusick 	if ((flag & P_CONTROLT) && k->ki_p->ki_pgid == k->ki_p->ki_tpgid)
2614b88c807SRodney W. Grimes 		*cp++ = '+';
26275c13541SPoul-Henning Kamp 	if (flag & P_JAILED)
26375c13541SPoul-Henning Kamp 		*cp++ = 'J';
2644b88c807SRodney W. Grimes 	*cp = '\0';
2654b88c807SRodney W. Grimes 	(void)printf("%-*s", v->width, buf);
2664b88c807SRodney W. Grimes }
2674b88c807SRodney W. Grimes 
2684b88c807SRodney W. Grimes void
26946251ddeSWarner Losh pri(KINFO *k, VARENT *ve)
2704b88c807SRodney W. Grimes {
2714b88c807SRodney W. Grimes 	VAR *v;
2724b88c807SRodney W. Grimes 
2734b88c807SRodney W. Grimes 	v = ve->var;
2744c85452bSJake Burkholder 	(void)printf("%*d", v->width, k->ki_p->ki_pri.pri_level - PZERO);
2754b88c807SRodney W. Grimes }
2764b88c807SRodney W. Grimes 
2774b88c807SRodney W. Grimes void
27846251ddeSWarner Losh uname(KINFO *k, VARENT *ve)
2794b88c807SRodney W. Grimes {
2804b88c807SRodney W. Grimes 	VAR *v;
2814b88c807SRodney W. Grimes 
2824b88c807SRodney W. Grimes 	v = ve->var;
283e8eef4bbSJuli Mallett 	(void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_uid, 0));
2844b88c807SRodney W. Grimes }
2854b88c807SRodney W. Grimes 
2866a2d726bSJordan K. Hubbard int
28746251ddeSWarner Losh s_uname(KINFO *k)
2886a2d726bSJordan K. Hubbard {
2891f7d2501SKirk McKusick 	    return (strlen(user_from_uid(k->ki_p->ki_uid, 0)));
2906a2d726bSJordan K. Hubbard }
2916a2d726bSJordan K. Hubbard 
2924b88c807SRodney W. Grimes void
293e8eef4bbSJuli Mallett rgroupname(KINFO *k, VARENT *ve)
294e8eef4bbSJuli Mallett {
295e8eef4bbSJuli Mallett 	VAR *v;
296e8eef4bbSJuli Mallett 
297e8eef4bbSJuli Mallett 	v = ve->var;
298e8eef4bbSJuli Mallett 	(void)printf("%-*s", v->width, group_from_gid(k->ki_p->ki_rgid, 0));
299e8eef4bbSJuli Mallett }
300e8eef4bbSJuli Mallett 
301e8eef4bbSJuli Mallett int
302e8eef4bbSJuli Mallett s_rgroupname(KINFO *k)
303e8eef4bbSJuli Mallett {
304e8eef4bbSJuli Mallett 	return (strlen(group_from_gid(k->ki_p->ki_rgid, 0)));
305e8eef4bbSJuli Mallett }
306e8eef4bbSJuli Mallett 
307e8eef4bbSJuli Mallett void
30846251ddeSWarner Losh runame(KINFO *k, VARENT *ve)
3094b88c807SRodney W. Grimes {
3104b88c807SRodney W. Grimes 	VAR *v;
3114b88c807SRodney W. Grimes 
3124b88c807SRodney W. Grimes 	v = ve->var;
313e8eef4bbSJuli Mallett 	(void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_ruid, 0));
3144b88c807SRodney W. Grimes }
3154b88c807SRodney W. Grimes 
3166a2d726bSJordan K. Hubbard int
31746251ddeSWarner Losh s_runame(KINFO *k)
3186a2d726bSJordan K. Hubbard {
3191f7d2501SKirk McKusick 	    return (strlen(user_from_uid(k->ki_p->ki_ruid, 0)));
3206a2d726bSJordan K. Hubbard }
3216a2d726bSJordan K. Hubbard 
3224b88c807SRodney W. Grimes void
32346251ddeSWarner Losh tdev(KINFO *k, VARENT *ve)
3244b88c807SRodney W. Grimes {
3254b88c807SRodney W. Grimes 	VAR *v;
3264b88c807SRodney W. Grimes 	dev_t dev;
3274b88c807SRodney W. Grimes 	char buff[16];
3284b88c807SRodney W. Grimes 
3294b88c807SRodney W. Grimes 	v = ve->var;
3301f7d2501SKirk McKusick 	dev = k->ki_p->ki_tdev;
3314b88c807SRodney W. Grimes 	if (dev == NODEV)
3324b88c807SRodney W. Grimes 		(void)printf("%*s", v->width, "??");
3334b88c807SRodney W. Grimes 	else {
3344b88c807SRodney W. Grimes 		(void)snprintf(buff, sizeof(buff),
3354b88c807SRodney W. Grimes 		    "%d/%d", major(dev), minor(dev));
3364b88c807SRodney W. Grimes 		(void)printf("%*s", v->width, buff);
3374b88c807SRodney W. Grimes 	}
3384b88c807SRodney W. Grimes }
3394b88c807SRodney W. Grimes 
3404b88c807SRodney W. Grimes void
34146251ddeSWarner Losh tname(KINFO *k, VARENT *ve)
3424b88c807SRodney W. Grimes {
3434b88c807SRodney W. Grimes 	VAR *v;
3444b88c807SRodney W. Grimes 	dev_t dev;
3454b88c807SRodney W. Grimes 	char *ttname;
3464b88c807SRodney W. Grimes 
3474b88c807SRodney W. Grimes 	v = ve->var;
3481f7d2501SKirk McKusick 	dev = k->ki_p->ki_tdev;
3494b88c807SRodney W. Grimes 	if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
350c55931c7SPeter Wemm 		(void)printf("%*s ", v->width-1, "??");
3514b88c807SRodney W. Grimes 	else {
352efc18e2cSAndrey A. Chernov 		if (strncmp(ttname, "tty", 3) == 0 ||
353efc18e2cSAndrey A. Chernov 		    strncmp(ttname, "cua", 3) == 0)
3544b88c807SRodney W. Grimes 			ttname += 3;
355c55931c7SPeter Wemm 		(void)printf("%*.*s%c", v->width-1, v->width-1, ttname,
3561f7d2501SKirk McKusick 			k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-');
3574b88c807SRodney W. Grimes 	}
3584b88c807SRodney W. Grimes }
3594b88c807SRodney W. Grimes 
3604b88c807SRodney W. Grimes void
36146251ddeSWarner Losh longtname(KINFO *k, VARENT *ve)
3624b88c807SRodney W. Grimes {
3634b88c807SRodney W. Grimes 	VAR *v;
3644b88c807SRodney W. Grimes 	dev_t dev;
3654b88c807SRodney W. Grimes 	char *ttname;
3664b88c807SRodney W. Grimes 
3674b88c807SRodney W. Grimes 	v = ve->var;
3681f7d2501SKirk McKusick 	dev = k->ki_p->ki_tdev;
3694b88c807SRodney W. Grimes 	if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
3704b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "??");
3714b88c807SRodney W. Grimes 	else
3724b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, ttname);
3734b88c807SRodney W. Grimes }
3744b88c807SRodney W. Grimes 
3754b88c807SRodney W. Grimes void
37646251ddeSWarner Losh started(KINFO *k, VARENT *ve)
3774b88c807SRodney W. Grimes {
3784b88c807SRodney W. Grimes 	VAR *v;
3794b88c807SRodney W. Grimes 	static time_t now;
380f8ec5fe2SBruce Evans 	time_t then;
3814b88c807SRodney W. Grimes 	struct tm *tp;
3824b88c807SRodney W. Grimes 	char buf[100];
383f59105eeSAndrey A. Chernov 	static int  use_ampm = -1;
3844b88c807SRodney W. Grimes 
3854b88c807SRodney W. Grimes 	v = ve->var;
3861f7d2501SKirk McKusick 	if (!k->ki_valid) {
3874b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "-");
3884b88c807SRodney W. Grimes 		return;
3894b88c807SRodney W. Grimes 	}
3904b88c807SRodney W. Grimes 
391f59105eeSAndrey A. Chernov 	if (use_ampm < 0)
392f59105eeSAndrey A. Chernov 		use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
393f59105eeSAndrey A. Chernov 
3941f7d2501SKirk McKusick 	then = k->ki_p->ki_start.tv_sec;
395f8ec5fe2SBruce Evans 	tp = localtime(&then);
3964b88c807SRodney W. Grimes 	if (!now)
3974b88c807SRodney W. Grimes 		(void)time(&now);
3981f7d2501SKirk McKusick 	if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
39908017519SAndrey A. Chernov 		(void)strftime(buf, sizeof(buf) - 1,
40008017519SAndrey A. Chernov 		use_ampm ? "%l:%M%p" : "%k:%M  ", tp);
4011f7d2501SKirk McKusick 	} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
40208017519SAndrey A. Chernov 		(void)strftime(buf, sizeof(buf) - 1,
40308017519SAndrey A. Chernov 		use_ampm ? "%a%I%p" : "%a%H  ", tp);
4044b88c807SRodney W. Grimes 	} else
4054b88c807SRodney W. Grimes 		(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
4064b88c807SRodney W. Grimes 	(void)printf("%-*s", v->width, buf);
4074b88c807SRodney W. Grimes }
4084b88c807SRodney W. Grimes 
4094b88c807SRodney W. Grimes void
41046251ddeSWarner Losh lstarted(KINFO *k, VARENT *ve)
4114b88c807SRodney W. Grimes {
4124b88c807SRodney W. Grimes 	VAR *v;
413f8ec5fe2SBruce Evans 	time_t then;
4144b88c807SRodney W. Grimes 	char buf[100];
4154b88c807SRodney W. Grimes 
4164b88c807SRodney W. Grimes 	v = ve->var;
4171f7d2501SKirk McKusick 	if (!k->ki_valid) {
4184b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "-");
4194b88c807SRodney W. Grimes 		return;
4204b88c807SRodney W. Grimes 	}
4211f7d2501SKirk McKusick 	then = k->ki_p->ki_start.tv_sec;
422f8ec5fe2SBruce Evans 	(void)strftime(buf, sizeof(buf) -1, "%c", localtime(&then));
4234b88c807SRodney W. Grimes 	(void)printf("%-*s", v->width, buf);
4244b88c807SRodney W. Grimes }
4254b88c807SRodney W. Grimes 
4264b88c807SRodney W. Grimes void
42746251ddeSWarner Losh mtxname(KINFO *k, VARENT *ve)
428fd5f30bfSJohn Baldwin {
429fd5f30bfSJohn Baldwin 	VAR *v;
430fd5f30bfSJohn Baldwin 
431fd5f30bfSJohn Baldwin 	v = ve->var;
4321f7d2501SKirk McKusick 	if (k->ki_p->ki_kiflag & KI_MTXBLOCK) {
4331f7d2501SKirk McKusick 		if (k->ki_p->ki_mtxname[0] != 0)
434fd5f30bfSJohn Baldwin 			(void)printf("%-*.*s", v->width, v->width,
4351f7d2501SKirk McKusick 				      k->ki_p->ki_mtxname);
436fd5f30bfSJohn Baldwin 		else
437fd5f30bfSJohn Baldwin 			(void)printf("%-*s", v->width, "???");
438fd5f30bfSJohn Baldwin 	} else
439fd5f30bfSJohn Baldwin 		(void)printf("%-*s", v->width, "-");
440fd5f30bfSJohn Baldwin }
441fd5f30bfSJohn Baldwin 
442fd5f30bfSJohn Baldwin void
44346251ddeSWarner Losh wchan(KINFO *k, VARENT *ve)
4444b88c807SRodney W. Grimes {
4454b88c807SRodney W. Grimes 	VAR *v;
4464b88c807SRodney W. Grimes 
4474b88c807SRodney W. Grimes 	v = ve->var;
4481f7d2501SKirk McKusick 	if (k->ki_p->ki_wchan) {
4491f7d2501SKirk McKusick 		if (k->ki_p->ki_wmesg[0] != 0)
4504b88c807SRodney W. Grimes 			(void)printf("%-*.*s", v->width, v->width,
4511f7d2501SKirk McKusick 				      k->ki_p->ki_wmesg);
4524b88c807SRodney W. Grimes 		else
4533929d518SDoug Rabson 			(void)printf("%-*lx", v->width,
4547d1192a7SPeter Wemm 			    (long)k->ki_p->ki_wchan);
455d9a5f890SMatthew Dillon 	} else {
456d9a5f890SMatthew Dillon 		(void)printf("%-*s", v->width, "-");
457d9a5f890SMatthew Dillon 	}
458d9a5f890SMatthew Dillon }
459d9a5f890SMatthew Dillon 
460d9a5f890SMatthew Dillon void
461d9a5f890SMatthew Dillon mwchan(KINFO *k, VARENT *ve)
462d9a5f890SMatthew Dillon {
463d9a5f890SMatthew Dillon 	VAR *v;
464d9a5f890SMatthew Dillon 
465d9a5f890SMatthew Dillon 	v = ve->var;
466d9a5f890SMatthew Dillon 	if (k->ki_p->ki_wchan) {
467d9a5f890SMatthew Dillon 		if (k->ki_p->ki_wmesg[0] != 0)
468d9a5f890SMatthew Dillon 			(void)printf("%-*.*s", v->width, v->width,
469d9a5f890SMatthew Dillon 				      k->ki_p->ki_wmesg);
470d9a5f890SMatthew Dillon 		else
471d9a5f890SMatthew Dillon 			(void)printf("%-*lx", v->width,
472d9a5f890SMatthew Dillon 			    (long)k->ki_p->ki_wchan);
473ebc1fff9SMatthew Dillon 	} else if (k->ki_p->ki_kiflag & KI_MTXBLOCK) {
474d9a5f890SMatthew Dillon 		if (k->ki_p->ki_mtxname[0]) {
475d9a5f890SMatthew Dillon 			(void)printf("%-*.*s", v->width, v->width,
476d9a5f890SMatthew Dillon 			    k->ki_p->ki_mtxname);
477d9a5f890SMatthew Dillon 		} else {
478d9a5f890SMatthew Dillon 			(void)printf("%-*s", v->width, "???");
479d9a5f890SMatthew Dillon 		}
480ebc1fff9SMatthew Dillon 	} else {
4814b88c807SRodney W. Grimes 		(void)printf("%-*s", v->width, "-");
4824b88c807SRodney W. Grimes 	}
483ebc1fff9SMatthew Dillon }
4844b88c807SRodney W. Grimes 
4854a40c5e7SPeter Wemm #ifndef pgtok
4863a91de06SPoul-Henning Kamp #define pgtok(a)        (((a)*getpagesize())/1024)
4874a40c5e7SPeter Wemm #endif
4884b88c807SRodney W. Grimes 
4894b88c807SRodney W. Grimes void
49046251ddeSWarner Losh vsize(KINFO *k, VARENT *ve)
4914b88c807SRodney W. Grimes {
4924b88c807SRodney W. Grimes 	VAR *v;
4934b88c807SRodney W. Grimes 
4944b88c807SRodney W. Grimes 	v = ve->var;
4954b88c807SRodney W. Grimes 	(void)printf("%*d", v->width,
4961f7d2501SKirk McKusick 	    (k->ki_p->ki_size/1024));
4974b88c807SRodney W. Grimes }
4984b88c807SRodney W. Grimes 
4994b88c807SRodney W. Grimes void
50046251ddeSWarner Losh cputime(KINFO *k, VARENT *ve)
5014b88c807SRodney W. Grimes {
5024b88c807SRodney W. Grimes 	VAR *v;
5034b88c807SRodney W. Grimes 	long secs;
5044b88c807SRodney W. Grimes 	long psecs;	/* "parts" of a second. first micro, then centi */
5054b88c807SRodney W. Grimes 	char obuff[128];
5068073a93cSAndrey A. Chernov 	static char decimal_point = 0;
5074b88c807SRodney W. Grimes 
5088073a93cSAndrey A. Chernov 	if (!decimal_point)
5098073a93cSAndrey A. Chernov 		decimal_point = localeconv()->decimal_point[0];
5104b88c807SRodney W. Grimes 	v = ve->var;
5111f7d2501SKirk McKusick 	if (k->ki_p->ki_stat == SZOMB || !k->ki_valid) {
5125832a752SBruce Evans 		secs = 0;
5135832a752SBruce Evans 		psecs = 0;
5144b88c807SRodney W. Grimes 	} else {
5154b88c807SRodney W. Grimes 		/*
5164b88c807SRodney W. Grimes 		 * This counts time spent handling interrupts.  We could
5174b88c807SRodney W. Grimes 		 * fix this, but it is not 100% trivial (and interrupt
5184b88c807SRodney W. Grimes 		 * time fractions only work on the sparc anyway).	XXX
5194b88c807SRodney W. Grimes 		 */
5201f7d2501SKirk McKusick 		secs = k->ki_p->ki_runtime / 1000000;
5211f7d2501SKirk McKusick 		psecs = k->ki_p->ki_runtime % 1000000;
5224b88c807SRodney W. Grimes 		if (sumrusage) {
5231f7d2501SKirk McKusick 			secs += k->ki_p->ki_childtime.tv_sec;
5241f7d2501SKirk McKusick 			psecs += k->ki_p->ki_childtime.tv_usec;
5254b88c807SRodney W. Grimes 		}
5264b88c807SRodney W. Grimes 		/*
5274b88c807SRodney W. Grimes 		 * round and scale to 100's
5284b88c807SRodney W. Grimes 		 */
5295832a752SBruce Evans 		psecs = (psecs + 5000) / 10000;
5305832a752SBruce Evans 		secs += psecs / 100;
5315832a752SBruce Evans 		psecs = psecs % 100;
5325832a752SBruce Evans 	}
5334b88c807SRodney W. Grimes 	(void)snprintf(obuff, sizeof(obuff),
5348073a93cSAndrey A. Chernov 	    "%3ld:%02ld%c%02ld", secs/60, secs%60, decimal_point, psecs);
5354b88c807SRodney W. Grimes 	(void)printf("%*s", v->width, obuff);
5364b88c807SRodney W. Grimes }
5374b88c807SRodney W. Grimes 
53876e1a9feSJuli Mallett void
53976e1a9feSJuli Mallett elapsed(KINFO *k, VARENT *ve)
54076e1a9feSJuli Mallett {
54176e1a9feSJuli Mallett 	VAR *v;
54276e1a9feSJuli Mallett 	time_t secs;
54376e1a9feSJuli Mallett 	char obuff[128];
54476e1a9feSJuli Mallett 	static time_t now;
54576e1a9feSJuli Mallett 
54676e1a9feSJuli Mallett 	v = ve->var;
54776e1a9feSJuli Mallett 
54876e1a9feSJuli Mallett 	if (!now)
54976e1a9feSJuli Mallett 		time(&now);
55076e1a9feSJuli Mallett 	secs = now - k->ki_p->ki_start.tv_sec;
55176e1a9feSJuli Mallett 	(void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld", secs/60, secs%60);
55276e1a9feSJuli Mallett 	(void)printf("%*s", v->width, obuff);
55376e1a9feSJuli Mallett }
55476e1a9feSJuli Mallett 
5554b88c807SRodney W. Grimes double
556871e8d8cSMark Murray getpcpu(const KINFO *k)
5574b88c807SRodney W. Grimes {
5584b88c807SRodney W. Grimes 	static int failure;
5594b88c807SRodney W. Grimes 
5604b88c807SRodney W. Grimes 	if (!nlistread)
5614b88c807SRodney W. Grimes 		failure = donlist();
5624b88c807SRodney W. Grimes 	if (failure)
5634b88c807SRodney W. Grimes 		return (0.0);
5644b88c807SRodney W. Grimes 
5654b88c807SRodney W. Grimes #define	fxtofl(fixpt)	((double)(fixpt) / fscale)
5664b88c807SRodney W. Grimes 
5674b88c807SRodney W. Grimes 	/* XXX - I don't like this */
568e0aa5ab7SJohn Baldwin 	if (k->ki_p->ki_swtime == 0 || (k->ki_p->ki_sflag & PS_INMEM) == 0)
5694b88c807SRodney W. Grimes 		return (0.0);
5704b88c807SRodney W. Grimes 	if (rawcpu)
5711f7d2501SKirk McKusick 		return (100.0 * fxtofl(k->ki_p->ki_pctcpu));
5721f7d2501SKirk McKusick 	return (100.0 * fxtofl(k->ki_p->ki_pctcpu) /
5731f7d2501SKirk McKusick 		(1.0 - exp(k->ki_p->ki_swtime * log(fxtofl(ccpu)))));
5744b88c807SRodney W. Grimes }
5754b88c807SRodney W. Grimes 
5764b88c807SRodney W. Grimes void
57746251ddeSWarner Losh pcpu(KINFO *k, VARENT *ve)
5784b88c807SRodney W. Grimes {
5794b88c807SRodney W. Grimes 	VAR *v;
5804b88c807SRodney W. Grimes 
5814b88c807SRodney W. Grimes 	v = ve->var;
5824b88c807SRodney W. Grimes 	(void)printf("%*.1f", v->width, getpcpu(k));
5834b88c807SRodney W. Grimes }
5844b88c807SRodney W. Grimes 
585871e8d8cSMark Murray static double
58646251ddeSWarner Losh getpmem(KINFO *k)
5874b88c807SRodney W. Grimes {
5884b88c807SRodney W. Grimes 	static int failure;
5894b88c807SRodney W. Grimes 	double fracmem;
5904b88c807SRodney W. Grimes 
5914b88c807SRodney W. Grimes 	if (!nlistread)
5924b88c807SRodney W. Grimes 		failure = donlist();
5934b88c807SRodney W. Grimes 	if (failure)
5944b88c807SRodney W. Grimes 		return (0.0);
5954b88c807SRodney W. Grimes 
596e0aa5ab7SJohn Baldwin 	if ((k->ki_p->ki_sflag & PS_INMEM) == 0)
5974b88c807SRodney W. Grimes 		return (0.0);
5984b88c807SRodney W. Grimes 	/* XXX want pmap ptpages, segtab, etc. (per architecture) */
5994b88c807SRodney W. Grimes 	/* XXX don't have info about shared */
60085012e7cSPeter Wemm 	fracmem = ((float)k->ki_p->ki_rssize)/mempages;
6014b88c807SRodney W. Grimes 	return (100.0 * fracmem);
6024b88c807SRodney W. Grimes }
6034b88c807SRodney W. Grimes 
6044b88c807SRodney W. Grimes void
60546251ddeSWarner Losh pmem(KINFO *k, VARENT *ve)
6064b88c807SRodney W. Grimes {
6074b88c807SRodney W. Grimes 	VAR *v;
6084b88c807SRodney W. Grimes 
6094b88c807SRodney W. Grimes 	v = ve->var;
6104b88c807SRodney W. Grimes 	(void)printf("%*.1f", v->width, getpmem(k));
6114b88c807SRodney W. Grimes }
6124b88c807SRodney W. Grimes 
6134b88c807SRodney W. Grimes void
61446251ddeSWarner Losh pagein(KINFO *k, VARENT *ve)
6154b88c807SRodney W. Grimes {
6164b88c807SRodney W. Grimes 	VAR *v;
6174b88c807SRodney W. Grimes 
6184b88c807SRodney W. Grimes 	v = ve->var;
6190fd510b7SJoerg Wunsch 	(void)printf("%*ld", v->width,
6201f7d2501SKirk McKusick 	    k->ki_valid ? k->ki_p->ki_rusage.ru_majflt : 0);
6214b88c807SRodney W. Grimes }
6224b88c807SRodney W. Grimes 
623871e8d8cSMark Murray /* ARGSUSED */
6244b88c807SRodney W. Grimes void
625871e8d8cSMark Murray maxrss(KINFO *k __unused, VARENT *ve)
6264b88c807SRodney W. Grimes {
6274b88c807SRodney W. Grimes 	VAR *v;
6284b88c807SRodney W. Grimes 
6294b88c807SRodney W. Grimes 	v = ve->var;
630940cca66SPeter Wemm 	/* XXX not yet */
6314b88c807SRodney W. Grimes 	(void)printf("%*s", v->width, "-");
6324b88c807SRodney W. Grimes }
6334b88c807SRodney W. Grimes 
6344b88c807SRodney W. Grimes void
63546251ddeSWarner Losh tsize(KINFO *k, VARENT *ve)
6364b88c807SRodney W. Grimes {
6374b88c807SRodney W. Grimes 	VAR *v;
6384b88c807SRodney W. Grimes 
6394b88c807SRodney W. Grimes 	v = ve->var;
6401f7d2501SKirk McKusick 	(void)printf("%*ld", v->width, (long)pgtok(k->ki_p->ki_tsize));
6414b88c807SRodney W. Grimes }
6424b88c807SRodney W. Grimes 
643ad863cacSSteve Price void
64446251ddeSWarner Losh priorityr(KINFO *k, VARENT *ve)
645ad863cacSSteve Price {
646ad863cacSSteve Price 	VAR *v;
647871e8d8cSMark Murray 	struct priority *lpri;
648ad863cacSSteve Price 	char str[8];
6494c85452bSJake Burkholder 	unsigned class, level;
650ad863cacSSteve Price 
651ad863cacSSteve Price 	v = ve->var;
652871e8d8cSMark Murray 	lpri = (struct priority *) ((char *)k + v->off);
653871e8d8cSMark Murray 	class = lpri->pri_class;
654871e8d8cSMark Murray 	level = lpri->pri_level;
6554c85452bSJake Burkholder 	switch (class) {
6564c85452bSJake Burkholder 	case PRI_REALTIME:
6574c85452bSJake Burkholder 		snprintf(str, sizeof(str), "real:%u", level);
658ad863cacSSteve Price 		break;
6594c85452bSJake Burkholder 	case PRI_TIMESHARE:
660ad863cacSSteve Price 		strncpy(str, "normal", sizeof(str));
661ad863cacSSteve Price 		break;
6624c85452bSJake Burkholder 	case PRI_IDLE:
6634c85452bSJake Burkholder 		snprintf(str, sizeof(str), "idle:%u", level);
664ad863cacSSteve Price 		break;
665ad863cacSSteve Price 	default:
6664c85452bSJake Burkholder 		snprintf(str, sizeof(str), "%u:%u", class, level);
667ad863cacSSteve Price 		break;
668ad863cacSSteve Price 	}
669ad863cacSSteve Price 	str[sizeof(str) - 1] = '\0';
670ad863cacSSteve Price 	(void)printf("%*s", v->width, str);
671ad863cacSSteve Price }
672ad863cacSSteve Price 
6734b88c807SRodney W. Grimes /*
6744b88c807SRodney W. Grimes  * Generic output routines.  Print fields from various prototype
6754b88c807SRodney W. Grimes  * structures.
6764b88c807SRodney W. Grimes  */
6774b88c807SRodney W. Grimes static void
67846251ddeSWarner Losh printval(char *bp, VAR *v)
6794b88c807SRodney W. Grimes {
6804b88c807SRodney W. Grimes 	static char ofmt[32] = "%";
681fdbec398SJuli Mallett 	const char *fcp;
682fdbec398SJuli Mallett 	char *cp;
6834b88c807SRodney W. Grimes 
6844b88c807SRodney W. Grimes 	cp = ofmt + 1;
6854b88c807SRodney W. Grimes 	fcp = v->fmt;
6864b88c807SRodney W. Grimes 	if (v->flag & LJUST)
6874b88c807SRodney W. Grimes 		*cp++ = '-';
6884b88c807SRodney W. Grimes 	*cp++ = '*';
6890fd510b7SJoerg Wunsch 	while ((*cp++ = *fcp++));
6904b88c807SRodney W. Grimes 
6914b88c807SRodney W. Grimes 	switch (v->type) {
6924b88c807SRodney W. Grimes 	case CHAR:
6934b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(char *)bp);
6944b88c807SRodney W. Grimes 		break;
6954b88c807SRodney W. Grimes 	case UCHAR:
6964b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(u_char *)bp);
6974b88c807SRodney W. Grimes 		break;
6984b88c807SRodney W. Grimes 	case SHORT:
6994b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(short *)bp);
7004b88c807SRodney W. Grimes 		break;
7014b88c807SRodney W. Grimes 	case USHORT:
7024b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(u_short *)bp);
7034b88c807SRodney W. Grimes 		break;
7043929d518SDoug Rabson 	case INT:
7053929d518SDoug Rabson 		(void)printf(ofmt, v->width, *(int *)bp);
7063929d518SDoug Rabson 		break;
7073929d518SDoug Rabson 	case UINT:
7083929d518SDoug Rabson 		(void)printf(ofmt, v->width, *(u_int *)bp);
7093929d518SDoug Rabson 		break;
7104b88c807SRodney W. Grimes 	case LONG:
7114b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(long *)bp);
7124b88c807SRodney W. Grimes 		break;
7134b88c807SRodney W. Grimes 	case ULONG:
7144b88c807SRodney W. Grimes 		(void)printf(ofmt, v->width, *(u_long *)bp);
7154b88c807SRodney W. Grimes 		break;
7164b88c807SRodney W. Grimes 	case KPTR:
7177d1192a7SPeter Wemm 		(void)printf(ofmt, v->width, *(u_long *)bp);
7184b88c807SRodney W. Grimes 		break;
7194b88c807SRodney W. Grimes 	default:
7204b88c807SRodney W. Grimes 		errx(1, "unknown type %d", v->type);
7214b88c807SRodney W. Grimes 	}
7224b88c807SRodney W. Grimes }
7234b88c807SRodney W. Grimes 
7244b88c807SRodney W. Grimes void
72546251ddeSWarner Losh kvar(KINFO *k, VARENT *ve)
7264b88c807SRodney W. Grimes {
7274b88c807SRodney W. Grimes 	VAR *v;
7284b88c807SRodney W. Grimes 
7294b88c807SRodney W. Grimes 	v = ve->var;
7301f7d2501SKirk McKusick 	printval((char *)((char *)k->ki_p + v->off), v);
7314b88c807SRodney W. Grimes }
7324b88c807SRodney W. Grimes 
7334b88c807SRodney W. Grimes void
73446251ddeSWarner Losh rvar(KINFO *k, VARENT *ve)
7354b88c807SRodney W. Grimes {
7364b88c807SRodney W. Grimes 	VAR *v;
7374b88c807SRodney W. Grimes 
7384b88c807SRodney W. Grimes 	v = ve->var;
7391f7d2501SKirk McKusick 	if (k->ki_valid)
7401f7d2501SKirk McKusick 		printval((char *)((char *)(&k->ki_p->ki_rusage) + v->off), v);
7414b88c807SRodney W. Grimes 	else
7424b88c807SRodney W. Grimes 		(void)printf("%*s", v->width, "-");
7434b88c807SRodney W. Grimes }
7447304f61fSBrian Feldman 
7457304f61fSBrian Feldman void
74646251ddeSWarner Losh lattr(KINFO *k, VARENT *ve)
7477304f61fSBrian Feldman {
7487304f61fSBrian Feldman 	VAR *v;
7497304f61fSBrian Feldman 
7507304f61fSBrian Feldman 	v = ve->var;
751e8eef4bbSJuli Mallett 	(void)printf("%-*d", v->width, get_lattr(k->ki_p->ki_pid));
7527304f61fSBrian Feldman }
753