NetBSD/bin/ps/print.c

778 lines
14 KiB
C
Raw Normal View History

/* $NetBSD: print.c,v 1.51 2000/05/26 03:04:28 simonb Exp $ */
1995-03-21 12:01:59 +03:00
1993-03-21 12:45:37 +03:00
/*-
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
__RCSID("$NetBSD: print.c,v 1.51 2000/05/26 03:04:28 simonb 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 <vm/vm.h>
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
#include <err.h>
#include <kvm.h>
1994-05-09 07:31:07 +04:00
#include <math.h>
#include <nlist.h>
#include <pwd.h>
1994-05-09 07:31:07 +04:00
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
1994-05-09 07:31:07 +04:00
#include <tzfile.h>
#include <unistd.h>
1994-05-09 07:31:07 +04:00
#include "ps.h"
static char *cmdpart __P((char *));
1997-07-21 00:37:53 +04:00
static void printval __P((char *, VAR *));
static int titlecmp __P((char *, char **));
1997-03-19 08:45:27 +03:00
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))
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()
{
1994-05-09 07:31:07 +04:00
VAR *v;
struct varent *vent;
1993-03-21 12:45:37 +03:00
for (vent = vhead; vent; vent = vent->next) {
v = vent->var;
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
1994-05-09 07:31:07 +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');
1993-03-21 12:45:37 +03: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) &&
title[namelen+0] == ':' &&
title[namelen+1] == ' ')
return (0);
return (1);
}
1994-05-09 07:31:07 +04:00
void
command(ki, ve)
struct kinfo_proc2 *ki;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
int left;
char **argv, **p, *name;
1993-03-21 12:45:37 +03:00
1994-05-09 07:31:07 +04:00
v = ve->var;
if (ve->next != NULL || termwidth != UNLIMITED) {
if (ve->next == NULL) {
1994-05-09 07:31:07 +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;
} else
left = v->width;
} else
left = -1;
if (needenv && kd) {
argv = kvm_getenvv2(kd, ki, termwidth);
1997-07-21 00:37:53 +04:00
if ((p = argv) != NULL) {
while (*p) {
fmt_puts(*p, &left);
p++;
fmt_putc(' ', &left);
}
1993-03-21 12:45:37 +03:00
}
}
if (needcomm) {
name = ki->p_comm;
if (!commandonly) {
argv = NULL;
if (!use_procfs)
argv = kvm_getargv2(kd, ki, termwidth);
else
argv = procfs_getargv(ki, termwidth);
1997-07-21 00:37:53 +04:00
if ((p = argv) != NULL) {
while (*p) {
fmt_puts(*p, &left);
p++;
fmt_putc(' ', &left);
}
}
if (titlecmp(name, argv)) {
fmt_putc('(', &left);
fmt_puts(name, &left);
fmt_putc(')', &left);
}
if (use_procfs && argv) {
free(argv[0]);
free(argv);
}
} else {
fmt_puts(name, &left);
}
}
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
ucomm(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%-*s", v->width, k->p_comm);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
logname(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1997-03-19 08:45:27 +03:00
int n;
1994-05-09 07:31:07 +04:00
v = ve->var;
1997-03-19 08:45:27 +03:00
n = min(v->width, MAXLOGNAME);
(void)printf("%-*.*s", n, n, k->p_login);
1997-03-19 08:45:27 +03:00
if (v->width > n)
(void)printf("%*s", v->width - n, "");
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
state(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03: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
is_zombie = 0;
1994-05-09 07:31:07 +04:00
v = ve->var;
flag = k->p_flag;
1994-05-09 07:31:07 +04:00
cp = buf;
1993-03-21 12:45:37 +03: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) */
*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:
case SDEAD:
1993-03-21 12:45:37 +03:00
*cp = 'Z';
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';
if (k->p_nice < NZERO)
1993-03-21 12:45:37 +03:00
*cp++ = '<';
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';
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';
if ((flag & P_SYSTEM) || k->p_holdcnt)
1993-03-21 12:45:37 +03:00
*cp++ = 'L';
if (k->p_eflag & EPROC_SLEADER)
1993-03-21 12:45:37 +03:00
*cp++ = 's';
if ((flag & P_CONTROLT) && k->p__pgid == k->p_tpgid)
1993-03-21 12:45:37 +03:00
*cp++ = '+';
*cp = '\0';
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, buf);
1993-03-21 12:45:37 +03:00
}
void
pnice(k, ve)
struct kinfo_proc2 *k;
VARENT *ve;
{
VAR *v;
v = ve->var;
(void)printf("%*d", v->width, k->p_nice - NZERO);
}
1994-05-09 07:31:07 +04:00
void
pri(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width, k->p_priority - PZERO);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
uname(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%-*s",
(int)v->width, user_from_uid(k->p_uid, 0));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
runame(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%-*s",
(int)v->width, user_from_uid(k->p_ruid, 0));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
tdev(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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;
dev = k->p_tdev;
1993-03-21 12:45:37 +03:00
if (dev == NODEV)
1994-05-09 07:31:07 +04:00
(void)printf("%*s", v->width, "??");
1993-03-21 12:45:37 +03:00
else {
1994-05-09 07:31:07 +04:00
(void)snprintf(buff, sizeof(buff),
"%d/%d", major(dev), minor(dev));
(void)printf("%*s", v->width, buff);
1993-03-21 12:45:37 +03:00
}
}
1994-05-09 07:31:07 +04:00
void
tname(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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;
dev = k->p_tdev;
1993-03-21 12:45:37 +03:00
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "??");
1993-03-21 12:45:37 +03:00
else {
if (strncmp(ttname, "tty", 3) == 0 ||
strncmp(ttname, "dty", 3) == 0)
1993-03-21 12:45:37 +03:00
ttname += 3;
1994-05-09 07:31:07 +04:00
(void)printf("%*.*s%c", v->width-1, v->width-1, ttname,
k->p_eflag & EPROC_CTTY ? ' ' : '-');
1993-03-21 12:45:37 +03:00
}
}
1994-05-09 07:31:07 +04:00
void
longtname(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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;
dev = k->p_tdev;
1993-03-21 12:45:37 +03:00
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "??");
1993-03-21 12:45:37 +03:00
else
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, ttname);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
started(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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;
char buf[100];
1994-05-09 07:31:07 +04:00
v = ve->var;
if (!k->p_uvalid) {
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "-");
1993-03-21 12:45:37 +03:00
return;
}
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);
if (now - k->p_ustart_sec < 24 * SECSPERHOUR) {
1994-05-09 07:31:07 +04:00
/* I *hate* SCCS... */
static char fmt[] = __CONCAT("%l:%", "M%p");
(void)strftime(buf, sizeof(buf) - 1, fmt, tp);
} else if (now - k->p_ustart_sec < 7 * SECSPERDAY) {
1994-05-09 07:31:07 +04:00
/* I *hate* SCCS... */
static char fmt[] = __CONCAT("%a%", "I%p");
(void)strftime(buf, sizeof(buf) - 1, fmt, tp);
1993-03-21 12:45:37 +03:00
} else
1994-05-09 07:31:07 +04:00
(void)strftime(buf, sizeof(buf) - 1, "%e%b%y", tp);
(void)printf("%-*s", v->width, buf);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
lstarted(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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;
if (!k->p_uvalid) {
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, "-");
1993-03-21 12:45:37 +03:00
return;
}
startt = k->p_ustart_sec;
(void)strftime(buf, sizeof(buf) -1, "%c",
1995-06-07 20:29:30 +04:00
localtime(&startt));
1994-05-09 07:31:07 +04:00
(void)printf("%-*s", v->width, buf);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
wchan(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
1997-03-19 08:45:27 +03:00
int n;
1994-05-09 07:31:07 +04:00
v = ve->var;
if (k->p_wchan) {
if (k->p_wmesg) {
1997-03-19 08:45:27 +03:00
n = min(v->width, WMESGLEN);
(void)printf("%-*.*s", n, n, k->p_wmesg);
1997-03-19 08:45:27 +03:00
if (v->width > n)
(void)printf("%*s", v->width - n, "");
} else
1994-12-23 16:19:41 +03:00
(void)printf("%-*lx", v->width,
(long)k->p_wchan);
1993-03-21 12:45:37 +03:00
} else
1994-05-09 07:31:07 +04:00
(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
vsize(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width,
pgtok(k->p_vm_dsize + k->p_vm_ssize + k->p_vm_tsize));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
rssize(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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 */
(void)printf("%*d", v->width, pgtok(k->p_vm_rssize));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
p_rssize(k, ve) /* doesn't account for text */
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width, pgtok(k->p_vm_rssize));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
cputime(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
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 */
char obuff[128];
1994-05-09 07:31:07 +04:00
v = ve->var;
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
*/
secs = k->p_rtime_sec;
psecs = k->p_rtime_usec;
1993-03-21 12:45:37 +03:00
if (sumrusage) {
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;
}
1994-05-09 07:31:07 +04:00
(void)snprintf(obuff, sizeof(obuff),
"%3ld:%02ld.%02ld", secs/60, secs%60, psecs);
(void)printf("%*s", v->width, obuff);
1993-03-21 12:45:37 +03:00
}
double
getpcpu(k)
struct kinfo_proc2 *k;
1993-03-21 12:45:37 +03:00
{
static int failure;
if (!nlistread)
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 */
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)
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
pcpu(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*.1f", v->width, getpcpu(k));
1993-03-21 12:45:37 +03:00
}
double
getpmem(k)
struct kinfo_proc2 *k;
1993-03-21 12:45:37 +03:00
{
static int failure;
double fracmem;
int szptudot;
if (!nlistread)
failure = (kd) ? donlist() : 1;
1993-03-21 12:45:37 +03:00
if (failure)
return (0.0);
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 */
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
pmem(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*.1f", v->width, getpmem(k));
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
pagein(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*lld", v->width,
k->p_uvalid ? (long long)k->p_uru_majflt : 0);
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
maxrss(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
1998-02-06 07:47:30 +03:00
(void)printf("%*s", v->width, "-");
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
tsize(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
1993-03-21 12:45:37 +03:00
{
1994-05-09 07:31:07 +04:00
VAR *v;
v = ve->var;
(void)printf("%*d", v->width, pgtok(k->p_vm_tsize));
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
1993-03-21 12:45:37 +03:00
printval(bp, v)
char *bp;
VAR *v;
{
static char ofmt[32] = "%";
1994-05-09 07:31:07 +04:00
char *fcp, *cp;
enum type type;
1993-03-21 12:45:37 +03:00
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
/*
* 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))
1993-03-21 12:45:37 +03:00
switch (v->type) {
case INT32:
if (sizeof(int32_t) == sizeof(int))
type = INT;
else if (sizeof(int32_t) == sizeof(long))
type = LONG;
else
errx(1, "unknown conversion for type %d", v->type);
break;
case UINT32:
if (sizeof(u_int32_t) == sizeof(u_int))
type = UINT;
else if (sizeof(u_int32_t) == sizeof(u_long))
type = ULONG;
else
errx(1, "unknown conversion for type %d", v->type);
break;
default:
type = v->type;
break;
}
switch (type) {
1993-03-21 12:45:37 +03:00
case CHAR:
(void)printf(ofmt, v->width, GET(char));
1993-03-21 12:45:37 +03:00
break;
case UCHAR:
(void)printf(ofmt, v->width, CHK_INF127(GET(u_char)));
1993-03-21 12:45:37 +03:00
break;
case SHORT:
(void)printf(ofmt, v->width, GET(short));
1993-03-21 12:45:37 +03:00
break;
case USHORT:
(void)printf(ofmt, v->width, CHK_INF127(GET(u_short)));
1993-03-21 12:45:37 +03:00
break;
case INT:
(void)printf(ofmt, v->width, GET(int));
break;
case UINT:
(void)printf(ofmt, v->width, CHK_INF127(GET(u_int)));
break;
1993-03-21 12:45:37 +03:00
case LONG:
(void)printf(ofmt, v->width, GET(long));
1993-03-21 12:45:37 +03:00
break;
case ULONG:
(void)printf(ofmt, v->width, CHK_INF127(GET(u_long)));
1993-03-21 12:45:37 +03:00
break;
case KPTR:
(void)printf(ofmt, v->width, GET(u_long));
1993-03-21 12:45:37 +03:00
break;
case KPTR24:
(void)printf(ofmt, v->width, GET(u_long) & 0xffffff);
break;
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--;
(void)printf(ofmt, v->width, &buf[i]);
}
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
}
#undef GET
#undef CHK_INF127
1993-03-21 12:45:37 +03:00
}
1994-05-09 07:31:07 +04:00
void
pvar(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
{
VAR *v;
v = ve->var;
printval((char *)k + v->off, v);
1994-05-09 07:31:07 +04:00
}
void
evar(k, ve)
struct kinfo_proc2 *k;
1994-05-09 07:31:07 +04:00
VARENT *ve;
{
VAR *v;
v = ve->var;
printval((char *)k + v->off, v);
1994-05-09 07:31:07 +04:00
}