2000-06-29 10:26:33 +04:00
|
|
|
/* $NetBSD: print.c,v 1.56 2000/06/29 06:27:33 mrg Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
2000-06-08 17:30:39 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Simon Burge.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1994-05-09 07:31:07 +04:00
|
|
|
* Copyright (c) 1990, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-07-21 00:37:53 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-21 12:01:59 +03:00
|
|
|
#if 0
|
1994-05-09 07:31:07 +04:00
|
|
|
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
|
1995-03-21 12:01:59 +03:00
|
|
|
#else
|
2000-06-29 10:26:33 +04:00
|
|
|
__RCSID("$NetBSD: print.c,v 1.56 2000/06/29 06:27:33 mrg Exp $");
|
1995-03-21 12:01:59 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ucred.h>
|
1994-05-09 07:31:07 +04:00
|
|
|
#include <sys/sysctl.h>
|
1998-02-06 07:47:30 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
#include <err.h>
|
1995-05-19 00:33:20 +04:00
|
|
|
#include <kvm.h>
|
1994-05-09 07:31:07 +04:00
|
|
|
#include <math.h>
|
|
|
|
#include <nlist.h>
|
1996-07-13 10:58:33 +04:00
|
|
|
#include <pwd.h>
|
1994-05-09 07:31:07 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-04-01 18:19:27 +04:00
|
|
|
#include <time.h>
|
1994-05-09 07:31:07 +04:00
|
|
|
#include <tzfile.h>
|
1994-12-04 10:11:37 +03:00
|
|
|
#include <unistd.h>
|
1994-05-09 07:31:07 +04:00
|
|
|
|
|
|
|
#include "ps.h"
|
|
|
|
|
1995-05-19 00:33:20 +04:00
|
|
|
static char *cmdpart __P((char *));
|
2000-06-07 08:57:59 +04:00
|
|
|
static void printval __P((void *, VAR *, int));
|
1998-07-28 22:41:59 +04:00
|
|
|
static int titlecmp __P((char *, char **));
|
1995-05-19 00:33:20 +04:00
|
|
|
|
2000-06-07 08:57:59 +04:00
|
|
|
static void doubleprintorsetwidth __P((VAR *, double, int, int));
|
|
|
|
static void intprintorsetwidth __P((VAR *, int, int));
|
|
|
|
static void strprintorsetwidth __P((VAR *, const char *, int));
|
|
|
|
|
1997-03-19 08:45:27 +03:00
|
|
|
#define min(a,b) ((a) <= (b) ? (a) : (b))
|
|
|
|
#define max(a,b) ((a) >= (b) ? (a) : (b))
|
|
|
|
|
1995-05-19 00:33:20 +04:00
|
|
|
static char *
|
|
|
|
cmdpart(arg0)
|
|
|
|
char *arg0;
|
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
printheader()
|
|
|
|
{
|
2000-06-07 08:57:59 +04:00
|
|
|
int len;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
struct varent *vent;
|
2000-06-07 08:57:59 +04:00
|
|
|
static int firsttime = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (vent = vhead; vent; vent = vent->next) {
|
|
|
|
v = vent->var;
|
2000-06-08 17:30:39 +04:00
|
|
|
if (firsttime) {
|
2000-06-07 08:57:59 +04:00
|
|
|
len = strlen(v->header);
|
|
|
|
if (len > v->width)
|
|
|
|
v->width = len;
|
|
|
|
totwidth += v->width + 1; /* +1 for space */
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
if (v->flag & LJUST) {
|
|
|
|
if (vent->next == NULL) /* last one */
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)printf("%s", v->header);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf("%-*s", v->width,
|
|
|
|
v->header);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)printf("%*s", v->width, v->header);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (vent->next != NULL)
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)putchar(' ');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)putchar('\n');
|
2000-06-08 17:30:39 +04:00
|
|
|
if (firsttime) {
|
2000-06-07 08:57:59 +04:00
|
|
|
firsttime = 0;
|
2000-06-08 17:30:39 +04:00
|
|
|
totwidth--; /* take off last space */
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1998-07-28 22:41:59 +04:00
|
|
|
static int
|
|
|
|
titlecmp(name, argv)
|
|
|
|
char *name;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
char *title;
|
|
|
|
int namelen;
|
|
|
|
|
|
|
|
if (argv == 0 || argv[0] == 0)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
title = cmdpart(argv[0]);
|
|
|
|
|
|
|
|
if (!strcmp(name, title))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (title[0] == '-' && !strcmp(name, title+1))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
namelen = strlen(name);
|
|
|
|
|
|
|
|
if (argv[1] == 0 &&
|
|
|
|
!strncmp(name, title, namelen) &&
|
2000-06-08 17:30:39 +04:00
|
|
|
title[namelen + 0] == ':' &&
|
|
|
|
title[namelen + 1] == ' ')
|
1998-07-28 22:41:59 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2000-06-07 08:57:59 +04:00
|
|
|
static void
|
|
|
|
doubleprintorsetwidth(v, val, prec, mode)
|
|
|
|
VAR *v;
|
|
|
|
double val;
|
|
|
|
int prec;
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
int fmtlen;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
if (val < 0.0 && val < v->longestnd) {
|
|
|
|
fmtlen = (int)log10(-val) + prec + 2;
|
|
|
|
v->longestnd = val;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
} else if (val > 0.0 && val > v->longestpd) {
|
|
|
|
fmtlen = (int)log10(val) + prec + 1;
|
|
|
|
v->longestpd = val;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("%*.*f", v->width, prec, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
intprintorsetwidth(v, val, mode)
|
|
|
|
VAR *v;
|
|
|
|
int val;
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
int fmtlen;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
if (val < 0 && val < v->longestn) {
|
|
|
|
fmtlen = (int)log10((double)-val) + 2;
|
|
|
|
v->longestn = val;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
} else if (val > 0 && val > v->longestp) {
|
|
|
|
fmtlen = (int)log10((double)val) + 1;
|
|
|
|
v->longestp = val;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
printf("%*d", v->width, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
strprintorsetwidth(v, str, mode)
|
|
|
|
VAR *v;
|
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
len = strlen(str);
|
|
|
|
if (len > v->width)
|
|
|
|
v->width = len;
|
|
|
|
} else {
|
|
|
|
if (v->flag & LJUST)
|
|
|
|
printf("%-*.*s", v->width, v->width, str);
|
|
|
|
else
|
|
|
|
printf("%*.*s", v->width, v->width, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
command(ki, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *ki;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
int left;
|
1998-07-28 22:41:59 +04:00
|
|
|
char **argv, **p, *name;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-06-08 17:30:39 +04:00
|
|
|
if (mode == WIDTHMODE)
|
2000-06-07 08:57:59 +04:00
|
|
|
return;
|
2000-06-08 17:30:39 +04:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
1995-05-19 00:33:20 +04:00
|
|
|
if (ve->next != NULL || termwidth != UNLIMITED) {
|
|
|
|
if (ve->next == NULL) {
|
2000-06-08 17:30:39 +04:00
|
|
|
left = termwidth - (totwidth - v->width);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (left < 1) /* already wrapped, just use std width */
|
|
|
|
left = v->width;
|
1995-05-19 00:33:20 +04:00
|
|
|
} else
|
|
|
|
left = v->width;
|
|
|
|
} else
|
|
|
|
left = -1;
|
2000-05-26 07:04:28 +04:00
|
|
|
if (needenv && kd) {
|
|
|
|
argv = kvm_getenvv2(kd, ki, termwidth);
|
1997-07-21 00:37:53 +04:00
|
|
|
if ((p = argv) != NULL) {
|
1995-05-19 00:33:20 +04:00
|
|
|
while (*p) {
|
|
|
|
fmt_puts(*p, &left);
|
|
|
|
p++;
|
|
|
|
fmt_putc(' ', &left);
|
1993-06-01 05:38:28 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-05-19 00:33:20 +04:00
|
|
|
}
|
|
|
|
if (needcomm) {
|
2000-05-26 07:04:28 +04:00
|
|
|
name = ki->p_comm;
|
1995-05-19 00:33:20 +04:00
|
|
|
if (!commandonly) {
|
1999-10-15 23:31:24 +04:00
|
|
|
argv = NULL;
|
1999-10-16 00:39:52 +04:00
|
|
|
if (!use_procfs)
|
2000-05-26 07:04:28 +04:00
|
|
|
argv = kvm_getargv2(kd, ki, termwidth);
|
1999-10-16 00:39:52 +04:00
|
|
|
else
|
2000-05-26 07:04:28 +04:00
|
|
|
argv = procfs_getargv(ki, termwidth);
|
1997-07-21 00:37:53 +04:00
|
|
|
if ((p = argv) != NULL) {
|
1995-05-19 00:33:20 +04:00
|
|
|
while (*p) {
|
|
|
|
fmt_puts(*p, &left);
|
|
|
|
p++;
|
|
|
|
fmt_putc(' ', &left);
|
|
|
|
}
|
|
|
|
}
|
1998-07-28 22:41:59 +04:00
|
|
|
if (titlecmp(name, argv)) {
|
1995-05-19 00:33:20 +04:00
|
|
|
fmt_putc('(', &left);
|
1998-07-28 22:41:59 +04:00
|
|
|
fmt_puts(name, &left);
|
1995-05-19 00:33:20 +04:00
|
|
|
fmt_putc(')', &left);
|
|
|
|
}
|
1999-10-16 00:39:52 +04:00
|
|
|
if (use_procfs && argv) {
|
1999-10-15 23:31:24 +04:00
|
|
|
free(argv[0]);
|
|
|
|
free(argv);
|
|
|
|
}
|
1995-05-19 00:33:20 +04:00
|
|
|
} else {
|
1998-07-28 22:41:59 +04:00
|
|
|
fmt_puts(name, &left);
|
1995-05-19 00:33:20 +04:00
|
|
|
}
|
|
|
|
}
|
1995-05-25 08:13:17 +04:00
|
|
|
if (ve->next && left > 0)
|
|
|
|
printf("%*s", left, "");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
ucomm(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, k->p_comm, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
logname(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, k->p_login, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
state(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-05-26 07:04:28 +04:00
|
|
|
int flag, is_zombie;
|
1994-05-09 07:31:07 +04:00
|
|
|
char *cp;
|
|
|
|
VAR *v;
|
1993-03-21 12:45:37 +03:00
|
|
|
char buf[16];
|
1994-05-09 07:31:07 +04:00
|
|
|
|
2000-05-26 07:04:28 +04:00
|
|
|
is_zombie = 0;
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
flag = k->p_flag;
|
1994-05-09 07:31:07 +04:00
|
|
|
cp = buf;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-05-26 07:04:28 +04:00
|
|
|
switch (k->p_stat) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
case SSTOP:
|
|
|
|
*cp = 'T';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSLEEP:
|
1994-05-05 06:04:10 +04:00
|
|
|
if (flag & P_SINTR) /* interuptable (long) */
|
2000-05-26 07:04:28 +04:00
|
|
|
*cp = k->p_slptime >= MAXSLP ? 'I' : 'S';
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-05-05 06:04:10 +04:00
|
|
|
*cp = 'D';
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SRUN:
|
|
|
|
case SIDL:
|
2000-05-26 04:42:34 +04:00
|
|
|
case SONPROC:
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = 'R';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SZOMB:
|
1999-07-23 12:56:13 +04:00
|
|
|
case SDEAD:
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = 'Z';
|
2000-05-26 07:04:28 +04:00
|
|
|
is_zombie = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*cp = '?';
|
|
|
|
}
|
|
|
|
cp++;
|
1994-05-05 06:04:10 +04:00
|
|
|
if (flag & P_INMEM) {
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
*cp++ = 'W';
|
2000-05-26 07:04:28 +04:00
|
|
|
if (k->p_nice < NZERO)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = '<';
|
2000-05-26 07:04:28 +04:00
|
|
|
else if (k->p_nice > NZERO)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'N';
|
1994-05-05 06:04:10 +04:00
|
|
|
if (flag & P_TRACED)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'X';
|
2000-05-26 07:04:28 +04:00
|
|
|
if (flag & P_WEXIT && !is_zombie)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'E';
|
1994-05-05 06:04:10 +04:00
|
|
|
if (flag & P_PPWAIT)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'V';
|
2000-05-26 07:04:28 +04:00
|
|
|
if ((flag & P_SYSTEM) || k->p_holdcnt)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'L';
|
2000-05-26 07:04:28 +04:00
|
|
|
if (k->p_eflag & EPROC_SLEADER)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 's';
|
2000-05-26 07:04:28 +04:00
|
|
|
if ((flag & P_CONTROLT) && k->p__pgid == k->p_tpgid)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = '+';
|
|
|
|
*cp = '\0';
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, buf, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1996-10-02 22:07:20 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
pnice(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1996-10-02 22:07:20 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1996-10-02 22:07:20 +04:00
|
|
|
{
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v, k->p_nice - NZERO, mode);
|
1996-10-02 22:07:20 +04:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
pri(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v, k->p_priority - PZERO, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
uname(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, user_from_uid(k->p_uid, 0), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
runame(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, user_from_uid(k->p_ruid, 0), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
tdev(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
dev_t dev;
|
|
|
|
char buff[16];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
dev = k->p_tdev;
|
2000-06-07 08:57:59 +04:00
|
|
|
if (dev == NODEV) {
|
|
|
|
/*
|
|
|
|
* Minimum width is width of header - we don't
|
|
|
|
* need to check it every time.
|
|
|
|
*/
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%*s", v->width, "??");
|
|
|
|
} else {
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)snprintf(buff, sizeof(buff),
|
|
|
|
"%d/%d", major(dev), minor(dev));
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, buff, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
tname(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
1993-03-21 12:45:37 +03:00
|
|
|
dev_t dev;
|
1998-07-27 21:06:48 +04:00
|
|
|
const char *ttname;
|
2000-06-07 08:57:59 +04:00
|
|
|
int noctty;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
dev = k->p_tdev;
|
2000-06-07 08:57:59 +04:00
|
|
|
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) {
|
|
|
|
/*
|
|
|
|
* Minimum width is width of header - we don't
|
|
|
|
* need to check it every time.
|
|
|
|
*/
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%-*s", v->width, "??");
|
|
|
|
} else {
|
1999-10-11 13:18:09 +04:00
|
|
|
if (strncmp(ttname, "tty", 3) == 0 ||
|
|
|
|
strncmp(ttname, "dty", 3) == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
ttname += 3;
|
2000-06-07 08:57:59 +04:00
|
|
|
noctty = !(k->p_eflag & EPROC_CTTY) ? 1 : 0;
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
int fmtlen;
|
|
|
|
|
|
|
|
fmtlen = strlen(ttname) + noctty;
|
|
|
|
if (v->width < fmtlen)
|
2000-06-08 04:51:10 +04:00
|
|
|
v->width = fmtlen;
|
2000-06-07 08:57:59 +04:00
|
|
|
} else {
|
|
|
|
if (noctty)
|
|
|
|
printf("%-*s-", v->width - 1, ttname);
|
|
|
|
else
|
|
|
|
printf("%-*s", v->width, ttname);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
longtname(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
1993-03-21 12:45:37 +03:00
|
|
|
dev_t dev;
|
1998-07-27 21:06:48 +04:00
|
|
|
const char *ttname;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
dev = k->p_tdev;
|
2000-06-07 08:57:59 +04:00
|
|
|
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL) {
|
|
|
|
/*
|
|
|
|
* Minimum width is width of header - we don't
|
|
|
|
* need to check it every time.
|
|
|
|
*/
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%-*s", v->width, "??");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strprintorsetwidth(v, ttname, mode);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
started(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
1993-03-21 12:45:37 +03:00
|
|
|
static time_t now;
|
1995-06-07 20:29:30 +04:00
|
|
|
time_t startt;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct tm *tp;
|
2000-06-07 08:57:59 +04:00
|
|
|
char buf[100], *cp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: The maximum width of this field is the same as the header
|
|
|
|
* "STARTED" for locales that have 3 letter abbreviated month
|
|
|
|
* names and 2 letter am/pm descriptions.
|
|
|
|
*/
|
|
|
|
if (mode == WIDTHMODE)
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
if (!k->p_uvalid) {
|
2000-06-07 08:57:59 +04:00
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%*s", v->width, "-");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-05-26 07:04:28 +04:00
|
|
|
startt = k->p_ustart_sec;
|
1995-06-07 20:29:30 +04:00
|
|
|
tp = localtime(&startt);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!now)
|
|
|
|
(void)time(&now);
|
2000-06-07 08:57:59 +04:00
|
|
|
if (now - k->p_ustart_sec < SECSPERDAY)
|
1994-05-09 07:31:07 +04:00
|
|
|
/* I *hate* SCCS... */
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)strftime(buf, sizeof(buf) - 1, "%l:%" "M%p", tp);
|
|
|
|
else if (now - k->p_ustart_sec < DAYSPERWEEK * SECSPERDAY)
|
1994-05-09 07:31:07 +04:00
|
|
|
/* I *hate* SCCS... */
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)strftime(buf, sizeof(buf) - 1, "%a%" "I%p", tp);
|
|
|
|
else
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
|
2000-06-07 08:57:59 +04:00
|
|
|
/* %e and %l can start with a space. */
|
|
|
|
cp = buf;
|
|
|
|
if (*cp == ' ')
|
|
|
|
cp++;
|
|
|
|
strprintorsetwidth(v, cp, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
lstarted(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
1995-06-07 20:29:30 +04:00
|
|
|
time_t startt;
|
1993-03-21 12:45:37 +03:00
|
|
|
char buf[100];
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
if (!k->p_uvalid) {
|
2000-06-07 08:57:59 +04:00
|
|
|
/*
|
|
|
|
* Minimum width is less than header - we don't
|
|
|
|
* need to check it every time.
|
|
|
|
*/
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%*s", v->width, "-");
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
}
|
2000-05-26 07:04:28 +04:00
|
|
|
startt = k->p_ustart_sec;
|
2000-06-07 08:57:59 +04:00
|
|
|
|
|
|
|
/* assume all times are the same length */
|
|
|
|
if (mode != WIDTHMODE || v->width == 0) {
|
|
|
|
(void)strftime(buf, sizeof(buf) -1, "%c",
|
|
|
|
localtime(&startt));
|
|
|
|
strprintorsetwidth(v, buf, mode);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
wchan(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
2000-06-07 08:57:59 +04:00
|
|
|
char *buf;
|
1994-05-09 07:31:07 +04:00
|
|
|
|
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
if (k->p_wchan) {
|
|
|
|
if (k->p_wmesg) {
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, k->p_wmesg, mode);
|
|
|
|
v->width = min(v->width, WMESGLEN);
|
|
|
|
} else {
|
|
|
|
(void)asprintf(&buf, "%-*llx", v->width,
|
|
|
|
(long long)k->p_wchan);
|
|
|
|
if (buf == NULL)
|
|
|
|
err(1, "%s", "");
|
|
|
|
strprintorsetwidth(v, buf, mode);
|
|
|
|
v->width = min(v->width, WMESGLEN);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%-*s", v->width, "-");
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-09-15 06:00:34 +04:00
|
|
|
#define pgtok(a) (((a)*getpagesize())/1024)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
vsize(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v,
|
|
|
|
pgtok(k->p_vm_dsize + k->p_vm_ssize + k->p_vm_tsize), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
rssize(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
1993-03-21 12:45:37 +03:00
|
|
|
/* XXX don't have info about shared */
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v, pgtok(k->p_vm_rssize), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
p_rssize(k, ve, mode) /* doesn't account for text */
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v, pgtok(k->p_vm_rssize), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
cputime(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
1993-03-21 12:45:37 +03:00
|
|
|
long secs;
|
|
|
|
long psecs; /* "parts" of a second. first micro, then centi */
|
2000-06-07 08:57:59 +04:00
|
|
|
int fmtlen;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2000-05-26 07:04:28 +04:00
|
|
|
if (P_ZOMBIE(k) || k->p_uvalid == 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
secs = 0;
|
|
|
|
psecs = 0;
|
|
|
|
} else {
|
1994-05-09 07:31:07 +04:00
|
|
|
/*
|
|
|
|
* This counts time spent handling interrupts. We could
|
|
|
|
* fix this, but it is not 100% trivial (and interrupt
|
|
|
|
* time fractions only work on the sparc anyway). XXX
|
|
|
|
*/
|
2000-05-26 07:04:28 +04:00
|
|
|
secs = k->p_rtime_sec;
|
|
|
|
psecs = k->p_rtime_usec;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (sumrusage) {
|
2000-05-26 07:04:28 +04:00
|
|
|
secs += k->p_uctime_sec;
|
|
|
|
psecs += k->p_uctime_usec;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* round and scale to 100's
|
|
|
|
*/
|
|
|
|
psecs = (psecs + 5000) / 10000;
|
|
|
|
secs += psecs / 100;
|
|
|
|
psecs = psecs % 100;
|
|
|
|
}
|
2000-06-07 08:57:59 +04:00
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
/*
|
|
|
|
* Ugg, this is the only field where a value of 0 longer
|
|
|
|
* than the column title, and log10(0) isn't good enough.
|
|
|
|
* Use SECSPERMIN, because secs is divided by that when
|
|
|
|
* passed to log10().
|
|
|
|
*/
|
|
|
|
if (secs == 0 && v->longestp == 0)
|
|
|
|
secs = SECSPERMIN;
|
|
|
|
if (secs > v->longestp) {
|
|
|
|
/* "+6" for the "%02ld.%02ld" in the printf() below */
|
|
|
|
fmtlen = (int)log10((double)secs / SECSPERMIN) + 1 + 6;
|
|
|
|
v->longestp = secs;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf("%*ld:%02ld.%02ld", v->width - 6, secs / SECSPERMIN,
|
|
|
|
secs % SECSPERMIN, psecs);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
getpcpu(k)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
static int failure;
|
|
|
|
|
|
|
|
if (!nlistread)
|
1999-10-15 23:31:24 +04:00
|
|
|
failure = (kd) ? donlist() : 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (failure)
|
|
|
|
return (0.0);
|
|
|
|
|
|
|
|
#define fxtofl(fixpt) ((double)(fixpt) / fscale)
|
|
|
|
|
|
|
|
/* XXX - I don't like this */
|
2000-05-26 07:04:28 +04:00
|
|
|
if (k->p_swtime == 0 || (k->p_flag & P_INMEM) == 0 ||
|
|
|
|
k->p_stat == SZOMB || k->p_stat == SDEAD)
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0.0);
|
|
|
|
if (rawcpu)
|
2000-05-26 07:04:28 +04:00
|
|
|
return (100.0 * fxtofl(k->p_pctcpu));
|
|
|
|
return (100.0 * fxtofl(k->p_pctcpu) /
|
|
|
|
(1.0 - exp(k->p_swtime * log(ccpu))));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
pcpu(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
doubleprintorsetwidth(v, getpcpu(k), 1, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
getpmem(k)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
static int failure;
|
|
|
|
double fracmem;
|
|
|
|
int szptudot;
|
|
|
|
|
|
|
|
if (!nlistread)
|
1999-10-15 23:31:24 +04:00
|
|
|
failure = (kd) ? donlist() : 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (failure)
|
|
|
|
return (0.0);
|
|
|
|
|
2000-05-26 07:04:28 +04:00
|
|
|
if ((k->p_flag & P_INMEM) == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
return (0.0);
|
|
|
|
/* XXX want pmap ptpages, segtab, etc. (per architecture) */
|
1994-11-03 07:33:17 +03:00
|
|
|
szptudot = USPACE/getpagesize();
|
1993-03-21 12:45:37 +03:00
|
|
|
/* XXX don't have info about shared */
|
2000-05-26 07:04:28 +04:00
|
|
|
fracmem = ((float)k->p_vm_rssize + szptudot)/mempages;
|
1993-03-21 12:45:37 +03:00
|
|
|
return (100.0 * fracmem);
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
pmem(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
doubleprintorsetwidth(v, getpmem(k), 1, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
pagein(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v, k->p_uvalid ? k->p_uru_majflt : 0, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
maxrss(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
/* No need to check width! */
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%*s", v->width, "-");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
tsize(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
intprintorsetwidth(v, pgtok(k->p_vm_tsize), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic output routines. Print fields from various prototype
|
|
|
|
* structures.
|
|
|
|
*/
|
1994-05-09 07:31:07 +04:00
|
|
|
static void
|
2000-06-07 08:57:59 +04:00
|
|
|
printval(bp, v, mode)
|
|
|
|
void *bp;
|
1993-03-21 12:45:37 +03:00
|
|
|
VAR *v;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
static char ofmt[32] = "%";
|
2000-06-07 08:57:59 +04:00
|
|
|
int width, vok, fmtlen;
|
|
|
|
char *fcp, *cp, *obuf;
|
1995-09-30 00:58:12 +03:00
|
|
|
enum type type;
|
2000-06-07 08:57:59 +04:00
|
|
|
long long val;
|
|
|
|
unsigned long long uval;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2000-06-07 08:57:59 +04:00
|
|
|
/*
|
|
|
|
* Note that the "INF127" check is nonsensical for types
|
|
|
|
* that are or can be signed.
|
|
|
|
*/
|
|
|
|
#define GET(type) (*(type *)bp)
|
|
|
|
#define CHK_INF127(n) (((n) > 127) && (v->flag & INF127) ? 127 : (n))
|
|
|
|
|
|
|
|
#define VSIGN 1
|
|
|
|
#define VUNSIGN 2
|
|
|
|
#define VPTR 3
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
vok = 0;
|
|
|
|
switch (v->type) {
|
|
|
|
case CHAR:
|
|
|
|
val = GET(char);
|
|
|
|
vok = VSIGN;
|
|
|
|
break;
|
|
|
|
case UCHAR:
|
|
|
|
uval = CHK_INF127(GET(u_char));
|
|
|
|
vok = VUNSIGN;
|
|
|
|
break;
|
|
|
|
case SHORT:
|
|
|
|
val = GET(short);
|
|
|
|
vok = VSIGN;
|
|
|
|
break;
|
|
|
|
case USHORT:
|
|
|
|
uval = CHK_INF127(GET(u_short));
|
|
|
|
vok = VUNSIGN;
|
|
|
|
break;
|
|
|
|
case INT32:
|
|
|
|
val = GET(int32_t);
|
|
|
|
vok = VSIGN;
|
|
|
|
break;
|
|
|
|
case INT:
|
|
|
|
val = GET(int);
|
|
|
|
vok = VSIGN;
|
|
|
|
break;
|
|
|
|
case UINT:
|
|
|
|
case UINT32:
|
|
|
|
uval = CHK_INF127(GET(u_int));
|
|
|
|
vok = VUNSIGN;
|
|
|
|
break;
|
|
|
|
case LONG:
|
|
|
|
val = GET(long);
|
|
|
|
vok = VSIGN;
|
|
|
|
break;
|
|
|
|
case ULONG:
|
|
|
|
uval = CHK_INF127(GET(u_long));
|
|
|
|
vok = VUNSIGN;
|
|
|
|
break;
|
|
|
|
case KPTR:
|
|
|
|
uval = GET(u_long);
|
|
|
|
vok = VPTR;
|
|
|
|
break;
|
|
|
|
case KPTR24:
|
|
|
|
uval = GET(u_long) & 0xffffff;
|
|
|
|
vok = VPTR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* nothing... */;
|
|
|
|
}
|
|
|
|
switch (vok) {
|
|
|
|
case VSIGN:
|
|
|
|
if (val < 0 && val < v->longestn) {
|
|
|
|
fmtlen = (int)log10((double)-val) + 2;
|
|
|
|
v->longestn = val;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
} else if (val > 0 && val > v->longestp) {
|
|
|
|
fmtlen = (int)log10((double)val) + 1;
|
|
|
|
v->longestp = val;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VUNSIGN:
|
|
|
|
if (uval > v->longestu) {
|
|
|
|
fmtlen = (int)log10((double)uval) + 1;
|
|
|
|
v->longestu = uval;
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VPTR:
|
|
|
|
fmtlen = 0;
|
|
|
|
while (uval > 0) {
|
|
|
|
uval >>= 4;
|
|
|
|
fmtlen++;
|
|
|
|
}
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width = v->width;
|
1994-05-09 07:31:07 +04:00
|
|
|
cp = ofmt + 1;
|
|
|
|
fcp = v->fmt;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (v->flag & LJUST)
|
|
|
|
*cp++ = '-';
|
|
|
|
*cp++ = '*';
|
1997-07-21 00:37:53 +04:00
|
|
|
while ((*cp++ = *fcp++) != '\0')
|
|
|
|
continue;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
switch (v->type) {
|
1995-09-30 00:58:12 +03:00
|
|
|
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) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case CHAR:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, GET(char));
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
case UCHAR:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, CHK_INF127(GET(u_char)));
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
case SHORT:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, GET(short));
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
case USHORT:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, CHK_INF127(GET(u_short)));
|
|
|
|
return;
|
1995-05-09 02:39:24 +04:00
|
|
|
case INT:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, GET(int));
|
|
|
|
return;
|
1995-05-09 02:39:24 +04:00
|
|
|
case UINT:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, CHK_INF127(GET(u_int)));
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
case LONG:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, GET(long));
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
case ULONG:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, CHK_INF127(GET(u_long)));
|
|
|
|
return;
|
1993-03-21 12:45:37 +03:00
|
|
|
case KPTR:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, GET(u_long));
|
|
|
|
return;
|
1999-05-03 04:17:30 +04:00
|
|
|
case KPTR24:
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)printf(ofmt, width, GET(u_long) & 0xffffff);
|
|
|
|
return;
|
1999-04-16 17:34:32 +04:00
|
|
|
case SIGLIST:
|
|
|
|
{
|
|
|
|
sigset_t *s = (sigset_t *)(void *)bp;
|
|
|
|
size_t i;
|
|
|
|
#define SIGSETSIZE (sizeof(s->__bits) / sizeof(s->__bits[0]))
|
|
|
|
char buf[SIGSETSIZE * 8 + 1];
|
|
|
|
|
|
|
|
for (i = 0; i < SIGSETSIZE; i++)
|
|
|
|
(void)snprintf(&buf[i * 8], 9, "%.8x",
|
|
|
|
s->__bits[(SIGSETSIZE - 1) - i]);
|
|
|
|
|
|
|
|
/* Skip leading zeroes */
|
|
|
|
for (i = 0; buf[i]; i++)
|
|
|
|
if (buf[i] != '0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (buf[i] == '\0')
|
|
|
|
i--;
|
2000-06-07 08:57:59 +04:00
|
|
|
(void)asprintf(&obuf, ofmt, width, &buf[i]);
|
1999-04-16 17:34:32 +04:00
|
|
|
}
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1994-05-09 07:31:07 +04:00
|
|
|
errx(1, "unknown type %d", v->type);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2000-06-07 08:57:59 +04:00
|
|
|
if (obuf == NULL)
|
|
|
|
err(1, "%s", "");
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
/* Skip leading spaces. */
|
|
|
|
cp = strrchr(obuf, ' ');
|
|
|
|
if (cp == NULL)
|
|
|
|
cp = obuf;
|
|
|
|
else
|
|
|
|
cp++; /* skip last space */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cp = obuf;
|
|
|
|
strprintorsetwidth(v, cp, mode);
|
|
|
|
free(obuf);
|
1995-08-14 09:00:03 +04:00
|
|
|
#undef GET
|
1995-08-15 18:00:59 +04:00
|
|
|
#undef CHK_INF127
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-05-09 07:31:07 +04:00
|
|
|
|
|
|
|
void
|
2000-06-07 08:57:59 +04:00
|
|
|
pvar(k, ve, mode)
|
2000-05-26 07:04:28 +04:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VARENT *ve;
|
2000-06-07 08:57:59 +04:00
|
|
|
int mode;
|
1994-05-09 07:31:07 +04:00
|
|
|
{
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2000-06-07 08:57:59 +04:00
|
|
|
printval((char *)k + v->off, v, mode);
|
1994-05-09 07:31:07 +04:00
|
|
|
}
|