2014-11-15 04:58:34 +03:00
|
|
|
/* $NetBSD: print.c,v 1.123 2014/11/15 01:58:34 joerg Exp $ */
|
1995-03-21 12:01:59 +03:00
|
|
|
|
2000-06-08 17:30:39 +04:00
|
|
|
/*
|
2007-02-10 21:20:12 +03:00
|
|
|
* Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
|
2000-06-08 17:30:39 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 13:05:01 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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
|
2014-11-15 04:58:34 +03:00
|
|
|
__RCSID("$NetBSD: print.c,v 1.123 2014/11/15 01:58:34 joerg 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>
|
2003-01-18 13:52:16 +03:00
|
|
|
#include <sys/lwp.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#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>
|
2003-03-01 08:41:55 +03:00
|
|
|
#include <grp.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"
|
|
|
|
|
2004-03-27 15:09:28 +03:00
|
|
|
static char *cmdpart(char *);
|
2014-04-21 02:48:59 +04:00
|
|
|
static void printval(void *, VAR *, enum mode);
|
2004-03-27 15:09:28 +03:00
|
|
|
static int titlecmp(char *, char **);
|
1995-05-19 00:33:20 +04:00
|
|
|
|
2014-04-21 02:48:59 +04:00
|
|
|
static void doubleprintorsetwidth(VAR *, double, int, enum mode);
|
|
|
|
static void intprintorsetwidth(VAR *, int, enum mode);
|
|
|
|
static void strprintorsetwidth(VAR *, const char *, enum mode);
|
2000-06-07 08:57:59 +04:00
|
|
|
|
2004-03-27 17:49:13 +03:00
|
|
|
static time_t now;
|
|
|
|
|
1997-03-19 08:45:27 +03:00
|
|
|
#define min(a,b) ((a) <= (b) ? (a) : (b))
|
2003-03-06 12:04:21 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
iwidth(u_int64_t v)
|
|
|
|
{
|
|
|
|
u_int64_t nlim, lim;
|
|
|
|
int w = 1;
|
|
|
|
|
|
|
|
for (lim = 10; v >= lim; lim = nlim) {
|
|
|
|
nlim = lim * 10;
|
|
|
|
w++;
|
|
|
|
if (nlim < lim)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return w;
|
|
|
|
}
|
1997-03-19 08:45:27 +03:00
|
|
|
|
1995-05-19 00:33:20 +04:00
|
|
|
static char *
|
2004-03-27 15:09:28 +03:00
|
|
|
cmdpart(char *arg0)
|
1995-05-19 00:33:20 +04:00
|
|
|
{
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2004-03-27 15:09:28 +03:00
|
|
|
printheader(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
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;
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
static int noheader = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
/*
|
|
|
|
* If all the columns have user-specified null headers,
|
|
|
|
* don't print the blank header line at all.
|
|
|
|
*/
|
|
|
|
if (firsttime) {
|
|
|
|
SIMPLEQ_FOREACH(vent, &displaylist, next) {
|
|
|
|
if (vent->var->header[0])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (vent == NULL) {
|
|
|
|
noheader = 1;
|
|
|
|
firsttime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (noheader)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SIMPLEQ_FOREACH(vent, &displaylist, next) {
|
1993-03-21 12:45:37 +03:00
|
|
|
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) {
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(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);
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(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
|
|
|
}
|
|
|
|
|
2004-03-27 15:09:28 +03:00
|
|
|
/*
|
2004-04-23 06:58:27 +04:00
|
|
|
* Return 1 if the command name in the argument vector (u-area) does
|
2001-01-16 00:02:58 +03:00
|
|
|
* not match the command name (p_comm)
|
2001-01-15 19:16:51 +03:00
|
|
|
*/
|
1998-07-28 22:41:59 +04:00
|
|
|
static int
|
2004-03-27 15:09:28 +03:00
|
|
|
titlecmp(char *name, char **argv)
|
1998-07-28 22:41:59 +04:00
|
|
|
{
|
|
|
|
char *title;
|
|
|
|
int namelen;
|
|
|
|
|
2001-01-15 19:16:51 +03:00
|
|
|
|
2001-01-15 20:57:14 +03:00
|
|
|
/* no argument vector == no match; system processes/threads do that */
|
1998-07-28 22:41:59 +04:00
|
|
|
if (argv == 0 || argv[0] == 0)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
title = cmdpart(argv[0]);
|
|
|
|
|
2001-01-15 20:57:14 +03:00
|
|
|
/* the basename matches */
|
1998-07-28 22:41:59 +04:00
|
|
|
if (!strcmp(name, title))
|
|
|
|
return (0);
|
|
|
|
|
2001-01-15 20:57:14 +03:00
|
|
|
/* handle login shells, by skipping the leading - */
|
2004-03-27 15:44:08 +03:00
|
|
|
if (title[0] == '-' && !strcmp(name, title + 1))
|
1998-07-28 22:41:59 +04:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
namelen = strlen(name);
|
|
|
|
|
2001-01-15 20:57:14 +03:00
|
|
|
/* handle daemons that report activity as daemonname: activity */
|
1998-07-28 22:41:59 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
doubleprintorsetwidth(VAR *v, double val, int prec, enum mode mode)
|
2000-06-07 08:57:59 +04:00
|
|
|
{
|
|
|
|
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 {
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*.*f", v->width, prec, val);
|
2000-06-07 08:57:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-21 02:48:59 +04:00
|
|
|
intprintorsetwidth(VAR *v, int val, enum mode mode)
|
2000-06-07 08:57:59 +04:00
|
|
|
{
|
|
|
|
int fmtlen;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
if (val < 0 && val < v->longestn) {
|
|
|
|
v->longestn = val;
|
2003-03-06 12:04:21 +03:00
|
|
|
fmtlen = iwidth(-val) + 1;
|
2000-06-07 08:57:59 +04:00
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
} else if (val > 0 && val > v->longestp) {
|
|
|
|
v->longestp = val;
|
2003-03-06 12:04:21 +03:00
|
|
|
fmtlen = iwidth(val);
|
2000-06-07 08:57:59 +04:00
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
} else
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*d", v->width, val);
|
2000-06-07 08:57:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-04-21 02:48:59 +04:00
|
|
|
strprintorsetwidth(VAR *v, const char *str, enum mode mode)
|
2000-06-07 08:57:59 +04:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
len = strlen(str);
|
|
|
|
if (len > v->width)
|
|
|
|
v->width = len;
|
|
|
|
} else {
|
|
|
|
if (v->flag & LJUST)
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%-*.*s", v->width, v->width, str);
|
2000-06-07 08:57:59 +04:00
|
|
|
else
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*.*s", v->width, v->width, str);
|
2000-06-07 08:57:59 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
command(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *ki;
|
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
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
ki = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(ve, next) != NULL || termwidth != UNLIMITED) {
|
|
|
|
if (SIMPLEQ_NEXT(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) {
|
2002-06-19 12:11:55 +04:00
|
|
|
argv = kvm_getargv2(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);
|
2004-03-27 17:52:36 +03:00
|
|
|
if (v->flag & ARGV0)
|
|
|
|
break;
|
1995-05-19 00:33:20 +04:00
|
|
|
}
|
2004-03-27 17:52:36 +03:00
|
|
|
if (!(v->flag & ARGV0) &&
|
|
|
|
titlecmp(name, argv)) {
|
2001-08-07 18:46:09 +04:00
|
|
|
/*
|
|
|
|
* append the real command name within
|
2004-03-27 15:09:28 +03:00
|
|
|
* parentheses, if the command name
|
2001-08-07 18:46:09 +04:00
|
|
|
* does not match the one in the
|
|
|
|
* argument vector
|
|
|
|
*/
|
|
|
|
fmt_putc('(', &left);
|
|
|
|
fmt_puts(name, &left);
|
|
|
|
fmt_putc(')', &left);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Commands that don't set an argv vector
|
2001-08-24 10:37:03 +04:00
|
|
|
* are printed with square brackets if they
|
2001-08-24 05:48:22 +04:00
|
|
|
* are system commands. Otherwise they are
|
|
|
|
* printed within parentheses.
|
2001-08-07 18:46:09 +04:00
|
|
|
*/
|
2007-02-18 01:49:56 +03:00
|
|
|
if (ki->p_flag & P_SYSTEM) {
|
2001-08-24 05:48:22 +04:00
|
|
|
fmt_putc('[', &left);
|
|
|
|
fmt_puts(name, &left);
|
|
|
|
fmt_putc(']', &left);
|
|
|
|
} else {
|
|
|
|
fmt_putc('(', &left);
|
|
|
|
fmt_puts(name, &left);
|
|
|
|
fmt_putc(')', &left);
|
|
|
|
}
|
1999-10-15 23:31:24 +04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(ve, next) != NULL && left > 0)
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*s", left, "");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2003-03-01 08:41:55 +03:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
groups(void *arg, VARENT *ve, enum mode mode)
|
2003-03-01 08:41:55 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *ki;
|
|
|
|
VAR *v;
|
|
|
|
int left, i;
|
|
|
|
char buf[16], *p;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ki = arg;
|
|
|
|
v = ve->var;
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(ve, next) != NULL || termwidth != UNLIMITED) {
|
|
|
|
if (SIMPLEQ_NEXT(ve, next) == NULL) {
|
2003-03-01 08:41:55 +03:00
|
|
|
left = termwidth - (totwidth - v->width);
|
|
|
|
if (left < 1) /* already wrapped, just use std width */
|
|
|
|
left = v->width;
|
|
|
|
} else
|
|
|
|
left = v->width;
|
|
|
|
} else
|
|
|
|
left = -1;
|
|
|
|
|
2009-02-03 20:33:42 +03:00
|
|
|
if (ki->p_ngroups == 0)
|
2003-03-01 08:41:55 +03:00
|
|
|
fmt_putc('-', &left);
|
|
|
|
|
|
|
|
for (i = 0; i < ki->p_ngroups; i++) {
|
|
|
|
(void)snprintf(buf, sizeof(buf), "%d", ki->p_groups[i]);
|
|
|
|
if (i)
|
|
|
|
fmt_putc(' ', &left);
|
|
|
|
for (p = &buf[0]; *p; p++)
|
|
|
|
fmt_putc(*p, &left);
|
|
|
|
}
|
|
|
|
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(ve, next) != NULL && left > 0)
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*s", left, "");
|
2003-03-01 08:41:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
groupnames(void *arg, VARENT *ve, enum mode mode)
|
2003-03-01 08:41:55 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *ki;
|
|
|
|
VAR *v;
|
|
|
|
int left, i;
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ki = arg;
|
|
|
|
v = ve->var;
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(ve, next) != NULL || termwidth != UNLIMITED) {
|
|
|
|
if (SIMPLEQ_NEXT(ve, next) == NULL) {
|
2003-03-01 08:41:55 +03:00
|
|
|
left = termwidth - (totwidth - v->width);
|
|
|
|
if (left < 1) /* already wrapped, just use std width */
|
|
|
|
left = v->width;
|
|
|
|
} else
|
|
|
|
left = v->width;
|
|
|
|
} else
|
|
|
|
left = -1;
|
|
|
|
|
2009-02-03 20:37:02 +03:00
|
|
|
if (ki->p_ngroups == 0)
|
2003-03-01 08:41:55 +03:00
|
|
|
fmt_putc('-', &left);
|
|
|
|
|
|
|
|
for (i = 0; i < ki->p_ngroups; i++) {
|
|
|
|
if (i)
|
|
|
|
fmt_putc(' ', &left);
|
|
|
|
for (p = group_from_gid(ki->p_groups[i], 0); *p; p++)
|
|
|
|
fmt_putc(*p, &left);
|
|
|
|
}
|
|
|
|
|
* When all columns are given null customised headers, the blank header
line is not printed at all. This is specified in P1003.1-2004
(SUSv3), and is useful.
* Customised headers may contain embedded space, commas and equals
signs. To specify multiple customised headers, use multiple -o or -O
options. This is specified (for "-o", not for "-O") in P1003.1-2004
(SUSv3), and is useful.
* When a column is given a null (blank) customised header, it keeps its
default minimum width. This is specified in P1003.1-2004 (SUSv3), and
seems harmless.
* Fix a bug that made it impossible to print the same keyword multiple
times, with different customised headers each time. (Previously, the
last customised header was used for all instances of the keyword.)
* Make the behaviour of "-O" more useful. The first -O option adds
the default keywords only if there have not yet been any formatting
options, and multiple -O options now insert their keywords in adjacent
positions. Now {ps -j -O %cpu} is like {ps -j} with one extra column;
Previously, it would have had all the columns implied by "-j", plus
all the default columns, plus the extra column specified by "-O".
* Convert from home-grown linked lists to SIMPLEQ lists.
Discussed in tech-userlevel.
2006-10-02 21:54:35 +04:00
|
|
|
if (SIMPLEQ_NEXT(ve, next) != NULL && left > 0)
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*s", left, "");
|
2003-03-01 08:41:55 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
ucomm(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-10-30 01:32:53 +03:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
emul(void *arg, VARENT *ve, enum mode mode)
|
2006-10-30 01:32:53 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
strprintorsetwidth(v, k->p_ename, mode);
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
logname(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
state(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
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
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
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
|
|
|
|
2009-10-22 01:11:57 +04:00
|
|
|
/*
|
|
|
|
* NOTE: There are historical letters, which are no longer used:
|
|
|
|
*
|
|
|
|
* - W: indicated that process is swapped out.
|
|
|
|
* - L: indicated non-zero l_holdcnt (i.e. that process was
|
|
|
|
* prevented from swapping-out.
|
|
|
|
*
|
|
|
|
* These letters should not be used for new states to avoid
|
|
|
|
* conflicts with old applications which might depend on them.
|
|
|
|
*/
|
2000-05-26 07:04:28 +04:00
|
|
|
switch (k->p_stat) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
case LSSTOP:
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = 'T';
|
|
|
|
break;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
case LSSLEEP:
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & L_SINTR) /* interruptable (long) */
|
2009-02-14 11:02:04 +03:00
|
|
|
*cp = (int)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;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
case LSRUN:
|
|
|
|
case LSIDL:
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp = 'R';
|
|
|
|
break;
|
|
|
|
|
2008-10-19 06:39:08 +04:00
|
|
|
case LSONPROC:
|
|
|
|
*cp = 'O';
|
|
|
|
break;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
case LSZOMB:
|
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;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
case LSSUSPENDED:
|
|
|
|
*cp = 'U';
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
|
|
|
*cp = '?';
|
|
|
|
}
|
|
|
|
cp++;
|
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';
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & P_TRACED)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'X';
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & P_WEXIT && !is_zombie)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'E';
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & P_PPWAIT)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 'V';
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & P_SYSTEM)
|
2000-10-23 09:54:06 +04:00
|
|
|
*cp++ = 'K';
|
2000-05-26 07:04:28 +04:00
|
|
|
if (k->p_eflag & EPROC_SLEADER)
|
1993-03-21 12:45:37 +03:00
|
|
|
*cp++ = 's';
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & P_SA)
|
2003-01-18 13:52:16 +03:00
|
|
|
*cp++ = 'a';
|
|
|
|
else if (k->p_nlwps > 1)
|
|
|
|
*cp++ = 'l';
|
2007-02-18 01:49:56 +03: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
|
2014-04-21 02:48:59 +04:00
|
|
|
lstate(void *arg, VARENT *ve, enum mode mode)
|
1996-10-02 22:07:20 +04:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_lwp *k;
|
2012-02-13 16:55:28 +04:00
|
|
|
int flag;
|
2003-01-18 13:52:16 +03:00
|
|
|
char *cp;
|
1996-10-02 22:07:20 +04:00
|
|
|
VAR *v;
|
2003-01-18 13:52:16 +03:00
|
|
|
char buf[16];
|
1996-10-02 22:07:20 +04:00
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1996-10-02 22:07:20 +04:00
|
|
|
v = ve->var;
|
2003-01-18 13:52:16 +03:00
|
|
|
flag = k->l_flag;
|
|
|
|
cp = buf;
|
|
|
|
|
|
|
|
switch (k->l_stat) {
|
|
|
|
|
|
|
|
case LSSTOP:
|
|
|
|
*cp = 'T';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LSSLEEP:
|
2004-02-24 18:16:04 +03:00
|
|
|
if (flag & L_SINTR) /* interruptible (long) */
|
2009-02-14 11:02:04 +03:00
|
|
|
*cp = (int)k->l_slptime >= maxslp ? 'I' : 'S';
|
2003-01-18 13:52:16 +03:00
|
|
|
else
|
|
|
|
*cp = 'D';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LSRUN:
|
|
|
|
case LSIDL:
|
|
|
|
*cp = 'R';
|
|
|
|
break;
|
|
|
|
|
2011-01-23 00:09:51 +03:00
|
|
|
case LSONPROC:
|
|
|
|
*cp = 'O';
|
|
|
|
break;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
case LSZOMB:
|
2007-02-18 01:49:56 +03:00
|
|
|
case LSDEAD:
|
2003-01-18 13:52:16 +03:00
|
|
|
*cp = 'Z';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LSSUSPENDED:
|
|
|
|
*cp = 'U';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*cp = '?';
|
|
|
|
}
|
|
|
|
cp++;
|
2011-01-23 00:09:51 +03:00
|
|
|
if (flag & L_SYSTEM)
|
2011-01-22 23:55:58 +03:00
|
|
|
*cp++ = 'K';
|
2011-01-23 00:09:51 +03:00
|
|
|
if (flag & L_SA)
|
|
|
|
*cp++ = 'a';
|
2007-02-18 01:49:56 +03:00
|
|
|
if (flag & L_DETACHED)
|
2003-01-18 13:52:16 +03:00
|
|
|
*cp++ = '-';
|
|
|
|
*cp = '\0';
|
|
|
|
strprintorsetwidth(v, buf, mode);
|
1996-10-02 22:07:20 +04:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
pnice(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2003-01-18 13:52:16 +03:00
|
|
|
intprintorsetwidth(v, k->p_nice - NZERO, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
pri(void *arg, VARENT *ve, enum mode mode)
|
2003-01-18 13:52:16 +03:00
|
|
|
{
|
|
|
|
struct kinfo_lwp *l;
|
|
|
|
VAR *v;
|
2004-03-27 15:09:28 +03:00
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
l = arg;
|
|
|
|
v = ve->var;
|
2007-11-06 03:44:46 +03:00
|
|
|
intprintorsetwidth(v, l->l_priority, mode);
|
2003-01-18 13:52:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
uname(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
runame(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-03-01 08:41:55 +03:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
svuname(void *arg, VARENT *ve, enum mode mode)
|
2003-03-01 08:41:55 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
strprintorsetwidth(v, user_from_uid(k->p_svuid, 0), mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
gname(void *arg, VARENT *ve, enum mode mode)
|
2003-03-01 08:41:55 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
strprintorsetwidth(v, group_from_gid(k->p_gid, 0), mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
rgname(void *arg, VARENT *ve, enum mode mode)
|
2003-03-01 08:41:55 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
strprintorsetwidth(v, group_from_gid(k->p_rgid, 0), mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
svgname(void *arg, VARENT *ve, enum mode mode)
|
2003-03-01 08:41:55 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
strprintorsetwidth(v, group_from_gid(k->p_svgid, 0), mode);
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
tdev(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
dev_t dev;
|
|
|
|
char buff[16];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
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) {
|
|
|
|
if (mode == PRINTMODE)
|
2004-11-16 07:58:14 +03:00
|
|
|
(void)printf("%*s", v->width, "?");
|
2003-03-06 12:04:21 +03:00
|
|
|
else
|
|
|
|
if (v->width < 2)
|
|
|
|
v->width = 2;
|
2000-06-07 08:57:59 +04:00
|
|
|
} else {
|
1994-05-09 07:31:07 +04:00
|
|
|
(void)snprintf(buff, sizeof(buff),
|
2008-12-28 22:50:22 +03:00
|
|
|
"%lld/%lld", (long long)major(dev), (long long)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
|
2014-04-21 02:48:59 +04:00
|
|
|
tname(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
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;
|
2004-03-27 15:09:28 +03:00
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
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) {
|
|
|
|
if (mode == PRINTMODE)
|
2004-11-16 07:58:14 +03:00
|
|
|
(void)printf("%-*s", v->width, "?");
|
2003-03-06 12:04:21 +03:00
|
|
|
else
|
|
|
|
if (v->width < 2)
|
|
|
|
v->width = 2;
|
2000-06-07 08:57:59 +04:00
|
|
|
} else {
|
|
|
|
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)
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%-*s-", v->width - 1, ttname);
|
2000-06-07 08:57:59 +04:00
|
|
|
else
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%-*s", v->width, ttname);
|
2000-06-07 08:57:59 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
longtname(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
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
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
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) {
|
|
|
|
if (mode == PRINTMODE)
|
2004-11-16 07:58:14 +03:00
|
|
|
(void)printf("%-*s", v->width, "?");
|
2003-03-06 12:04:21 +03:00
|
|
|
else
|
|
|
|
if (v->width < 2)
|
|
|
|
v->width = 2;
|
|
|
|
} else {
|
2000-06-07 08:57:59 +04:00
|
|
|
strprintorsetwidth(v, ttname, mode);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
started(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
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
|
|
|
struct tm *tp;
|
2000-06-07 08:57:59 +04:00
|
|
|
char buf[100], *cp;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
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);
|
2004-03-27 17:49:13 +03:00
|
|
|
if (now == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
(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
|
2014-04-21 02:48:59 +04:00
|
|
|
lstarted(void *arg, VARENT *ve, enum mode mode)
|
2004-03-27 15:09:28 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
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];
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
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
|
|
|
}
|
|
|
|
|
2004-03-27 17:49:13 +03:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
elapsed(void *arg, VARENT *ve, enum mode mode)
|
2004-03-27 17:49:13 +03:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
int32_t origseconds, secs, mins, hours, days;
|
|
|
|
int fmtlen, printed_something;
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
if (k->p_uvalid == 0) {
|
|
|
|
origseconds = 0;
|
|
|
|
} else {
|
|
|
|
if (now == 0)
|
|
|
|
(void)time(&now);
|
|
|
|
origseconds = now - k->p_ustart_sec;
|
|
|
|
if (origseconds < 0) {
|
|
|
|
/*
|
|
|
|
* Don't try to be fancy if the machine's
|
|
|
|
* clock has been rewound to before the
|
|
|
|
* process "started".
|
|
|
|
*/
|
|
|
|
origseconds = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
secs = origseconds;
|
|
|
|
mins = secs / SECSPERMIN;
|
|
|
|
secs %= SECSPERMIN;
|
|
|
|
hours = mins / MINSPERHOUR;
|
|
|
|
mins %= MINSPERHOUR;
|
|
|
|
days = hours / HOURSPERDAY;
|
|
|
|
hours %= HOURSPERDAY;
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
|
|
|
if (origseconds == 0)
|
|
|
|
/* non-zero so fmtlen is calculated at least once */
|
|
|
|
origseconds = 1;
|
|
|
|
|
|
|
|
if (origseconds > v->longestp) {
|
|
|
|
v->longestp = origseconds;
|
|
|
|
|
|
|
|
if (days > 0) {
|
|
|
|
/* +9 for "-hh:mm:ss" */
|
|
|
|
fmtlen = iwidth(days) + 9;
|
|
|
|
} else if (hours > 0) {
|
|
|
|
/* +6 for "mm:ss" */
|
|
|
|
fmtlen = iwidth(hours) + 6;
|
|
|
|
} else {
|
|
|
|
/* +3 for ":ss" */
|
|
|
|
fmtlen = iwidth(mins) + 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
} else {
|
2004-03-27 17:55:24 +03:00
|
|
|
printed_something = 0;
|
2004-03-27 17:49:13 +03:00
|
|
|
fmtlen = v->width;
|
|
|
|
|
|
|
|
if (days > 0) {
|
|
|
|
(void)printf("%*d", fmtlen - 9, days);
|
|
|
|
printed_something = 1;
|
|
|
|
} else if (fmtlen > 9) {
|
|
|
|
(void)printf("%*s", fmtlen - 9, "");
|
|
|
|
}
|
|
|
|
if (fmtlen > 9)
|
|
|
|
fmtlen = 9;
|
|
|
|
|
|
|
|
if (printed_something) {
|
|
|
|
(void)printf("-%.*d", fmtlen - 7, hours);
|
|
|
|
printed_something = 1;
|
|
|
|
} else if (hours > 0) {
|
|
|
|
(void)printf("%*d", fmtlen - 6, hours);
|
|
|
|
printed_something = 1;
|
|
|
|
} else if (fmtlen > 6) {
|
|
|
|
(void)printf("%*s", fmtlen - 6, "");
|
|
|
|
}
|
|
|
|
if (fmtlen > 6)
|
|
|
|
fmtlen = 6;
|
|
|
|
|
|
|
|
/* Don't need to set fmtlen or printed_something any more... */
|
|
|
|
if (printed_something) {
|
|
|
|
(void)printf(":%.*d", fmtlen - 4, mins);
|
|
|
|
} else if (mins > 0) {
|
|
|
|
(void)printf("%*d", fmtlen - 3, mins);
|
|
|
|
} else if (fmtlen > 3) {
|
|
|
|
(void)printf("%*s", fmtlen - 3, "0");
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)printf(":%.2d", secs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
wchan(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_lwp *l;
|
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
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
l = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2003-01-18 13:52:16 +03:00
|
|
|
if (l->l_wchan) {
|
2014-11-15 04:58:34 +03:00
|
|
|
if (l->l_wmesg[0]) {
|
2003-01-18 13:52:16 +03:00
|
|
|
strprintorsetwidth(v, l->l_wmesg, mode);
|
2003-03-06 12:04:21 +03:00
|
|
|
v->width = min(v->width, KI_WMESGLEN);
|
2000-06-07 08:57:59 +04:00
|
|
|
} else {
|
2003-03-06 12:04:21 +03:00
|
|
|
(void)asprintf(&buf, "%-*" PRIx64, v->width,
|
|
|
|
l->l_wchan);
|
2000-06-07 08:57:59 +04:00
|
|
|
if (buf == NULL)
|
|
|
|
err(1, "%s", "");
|
|
|
|
strprintorsetwidth(v, buf, mode);
|
2003-03-06 12:04:21 +03:00
|
|
|
v->width = min(v->width, KI_WMESGLEN);
|
2000-06-07 08:57:59 +04:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%-*s", v->width, "-");
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-13 07:42:15 +04:00
|
|
|
#define pgtok(a) (((a)*(size_t)getpagesize())/1024)
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
vsize(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
- add new RLIMIT_AS (aka RLIMIT_VMEM) resource that limits the total
address space available to processes. this limit exists in most other
modern unix variants, and like most of them, our defaults are unlimited.
remove the old mmap / rlimit.datasize hack.
- adds the VMCMD_STACK flag to all the stack-creation vmcmd callers.
it is currently unused, but was added a few years ago.
- add a pair of new process size values to kinfo_proc2{}. one is the
total size of the process memory map, and the other is the total size
adjusted for unused stack space (since most processes have a lot of
this...)
- patch sh, and csh to notice RLIMIT_AS. (in some cases, the alias
RLIMIT_VMEM was already present and used if availble.)
- patch ps, top and systat to notice the new k_vm_vsize member of
kinfo_proc2{}.
- update irix, svr4, svr4_32, linux and osf1 emulations to support
this information. (freebsd could be done, but that it's best left
as part of the full-update of compat/freebsd.)
this addresses PR 7897. it also gives correct memory usage values,
which have never been entirely correct (since mmap), and have been
very incorrect since jemalloc() was enabled.
tested on i386 and sparc64, build tested on several other platforms.
thanks to many folks for feedback and testing but most espcially
chuq and yamt for critical suggestions that lead to this patch not
having a special ugliness i wasn't happy with anyway :-)
2009-03-29 05:02:48 +04:00
|
|
|
intprintorsetwidth(v, pgtok(k->p_vm_msize), mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-05-09 07:31:07 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
rssize(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
p_rssize(void *arg, VARENT *ve, enum mode mode) /* doesn't account for text */
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-02-10 20:47:59 +03:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
cpuid(void *arg, VARENT *ve, enum mode mode)
|
2008-02-10 20:47:59 +03:00
|
|
|
{
|
|
|
|
struct kinfo_lwp *l;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
l = arg;
|
|
|
|
v = ve->var;
|
2010-05-31 07:18:33 +04:00
|
|
|
intprintorsetwidth(v, l->l_cpuid, mode);
|
2008-02-10 20:47:59 +03:00
|
|
|
}
|
|
|
|
|
2014-01-15 12:07:53 +04:00
|
|
|
static void
|
2014-04-21 02:48:59 +04:00
|
|
|
cputime1(int32_t secs, int32_t psecs, VAR *v, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2000-06-07 08:57:59 +04:00
|
|
|
int fmtlen;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2007-07-28 21:05:50 +04: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) {
|
|
|
|
/*
|
2004-03-27 15:11:55 +03:00
|
|
|
* Ugg, this is the only field where a value of 0 is longer
|
2003-03-06 12:04:21 +03:00
|
|
|
* than the column title.
|
2000-06-07 08:57:59 +04:00
|
|
|
* Use SECSPERMIN, because secs is divided by that when
|
2003-03-06 12:04:21 +03:00
|
|
|
* passed to iwidth().
|
2000-06-07 08:57:59 +04:00
|
|
|
*/
|
2003-03-06 12:04:21 +03:00
|
|
|
if (secs == 0)
|
2000-06-07 08:57:59 +04:00
|
|
|
secs = SECSPERMIN;
|
2003-03-06 12:04:21 +03:00
|
|
|
|
2000-06-07 08:57:59 +04:00
|
|
|
if (secs > v->longestp) {
|
|
|
|
v->longestp = secs;
|
2003-03-06 12:04:21 +03:00
|
|
|
/* "+6" for the ":%02ld.%02ld" in the printf() below */
|
|
|
|
fmtlen = iwidth(secs / SECSPERMIN) + 6;
|
2000-06-07 08:57:59 +04:00
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
} else {
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf("%*ld:%02ld.%02ld", v->width - 6,
|
|
|
|
(long)(secs / SECSPERMIN), (long)(secs % SECSPERMIN),
|
|
|
|
(long)psecs);
|
2000-06-07 08:57:59 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2014-01-15 12:07:53 +04:00
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
cputime(void *arg, VARENT *ve, enum mode mode)
|
2014-01-15 12:07:53 +04:00
|
|
|
{
|
|
|
|
struct kinfo_proc2 *k;
|
|
|
|
VAR *v;
|
|
|
|
int32_t secs;
|
|
|
|
int32_t psecs; /* "parts" of a second. first micro, then centi */
|
|
|
|
|
|
|
|
k = arg;
|
|
|
|
v = ve->var;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
if (sumrusage) {
|
|
|
|
secs += k->p_uctime_sec;
|
|
|
|
psecs += k->p_uctime_usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
cputime1(secs, psecs, v, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
lcputime(void *arg, VARENT *ve, enum mode mode)
|
2014-01-15 12:07:53 +04:00
|
|
|
{
|
|
|
|
struct kinfo_lwp *l;
|
|
|
|
VAR *v;
|
|
|
|
int32_t secs;
|
|
|
|
int32_t psecs; /* "parts" of a second. first micro, then centi */
|
|
|
|
|
|
|
|
l = arg;
|
|
|
|
v = ve->var;
|
|
|
|
|
|
|
|
secs = l->l_rtime_sec;
|
|
|
|
psecs = l->l_rtime_usec;
|
|
|
|
|
|
|
|
cputime1(secs, psecs, v, mode);
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
double
|
2012-03-20 22:42:28 +04:00
|
|
|
getpcpu(const 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)
|
|
|
|
|
2009-10-22 01:11:57 +04:00
|
|
|
if (k->p_swtime == 0 || k->p_realstat == SZOMB)
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
pcpu(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
2010-07-27 16:40:48 +04:00
|
|
|
double dbl;
|
1994-05-09 07:31:07 +04:00
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
v = ve->var;
|
2010-07-27 16:40:48 +04:00
|
|
|
dbl = getpcpu(k);
|
2010-07-28 21:39:54 +04:00
|
|
|
doubleprintorsetwidth(v, dbl, (dbl >= 99.95) ? 0 : 1, mode);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
2012-03-20 22:42:28 +04:00
|
|
|
getpmem(const 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);
|
|
|
|
|
|
|
|
/* XXX want pmap ptpages, segtab, etc. (per architecture) */
|
2001-07-14 10:53:43 +04: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
|
2014-04-21 02:48:59 +04:00
|
|
|
pmem(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
pagein(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
maxrss(void *arg, VARENT *ve, enum mode 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
|
2014-04-21 02:48:59 +04:00
|
|
|
tsize(void *arg, VARENT *ve, enum mode mode)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2003-01-18 13:52:16 +03:00
|
|
|
struct kinfo_proc2 *k;
|
1994-05-09 07:31:07 +04:00
|
|
|
VAR *v;
|
|
|
|
|
2003-01-18 13:52:16 +03:00
|
|
|
k = arg;
|
1994-05-09 07:31:07 +04:00
|
|
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
printval(void *bp, VAR *v, enum mode 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;
|
2005-06-26 23:10:48 +04:00
|
|
|
const char *fcp;
|
|
|
|
char *cp;
|
2003-03-06 12:04:21 +03:00
|
|
|
int64_t val;
|
|
|
|
u_int64_t uval;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2005-06-07 12:53:13 +04:00
|
|
|
val = 0; /* XXXGCC -Wuninitialized [hpcarm] */
|
|
|
|
uval = 0; /* XXXGCC -Wuninitialized [hpcarm] */
|
|
|
|
|
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:
|
2003-03-06 12:04:21 +03:00
|
|
|
uval = GET(u_int64_t);
|
2000-06-07 08:57:59 +04:00
|
|
|
vok = VPTR;
|
|
|
|
break;
|
|
|
|
case KPTR24:
|
2003-03-06 12:04:21 +03:00
|
|
|
uval = GET(u_int64_t);
|
2001-01-08 16:20:29 +03:00
|
|
|
uval &= 0xffffff;
|
2000-06-07 08:57:59 +04:00
|
|
|
vok = VPTR;
|
|
|
|
break;
|
Since kinfo_proc2 has many values that are 64-bit, ps needs to know
that they're 64-bit, and grab them out of memory appropriately. Otherwise,
big-endian systems get the wrong end of the 64-bit value and lose.
Keywords affected: inblk, majflt, minflt, msgrcv, msgsnd, nivcsw, nsigs,
nswap, nvcsw, and oublk.
2002-04-25 01:41:22 +04:00
|
|
|
case INT64:
|
2003-03-06 12:04:21 +03:00
|
|
|
val = GET(int64_t);
|
Since kinfo_proc2 has many values that are 64-bit, ps needs to know
that they're 64-bit, and grab them out of memory appropriately. Otherwise,
big-endian systems get the wrong end of the 64-bit value and lose.
Keywords affected: inblk, majflt, minflt, msgrcv, msgsnd, nivcsw, nsigs,
nswap, nvcsw, and oublk.
2002-04-25 01:41:22 +04:00
|
|
|
vok = VSIGN;
|
|
|
|
break;
|
|
|
|
case UINT64:
|
2003-03-06 12:04:21 +03:00
|
|
|
uval = CHK_INF127(GET(u_int64_t));
|
Since kinfo_proc2 has many values that are 64-bit, ps needs to know
that they're 64-bit, and grab them out of memory appropriately. Otherwise,
big-endian systems get the wrong end of the 64-bit value and lose.
Keywords affected: inblk, majflt, minflt, msgrcv, msgsnd, nivcsw, nsigs,
nswap, nvcsw, and oublk.
2002-04-25 01:41:22 +04:00
|
|
|
vok = VUNSIGN;
|
|
|
|
break;
|
|
|
|
|
2003-03-06 12:04:21 +03:00
|
|
|
case SIGLIST:
|
2000-06-07 08:57:59 +04:00
|
|
|
default:
|
|
|
|
/* nothing... */;
|
|
|
|
}
|
|
|
|
switch (vok) {
|
|
|
|
case VSIGN:
|
2003-03-06 12:04:21 +03:00
|
|
|
if (val < 0 && val < v->longestn) {
|
2000-06-07 08:57:59 +04:00
|
|
|
v->longestn = val;
|
2003-03-06 12:04:21 +03:00
|
|
|
fmtlen = iwidth(-val) + 1;
|
2000-06-07 08:57:59 +04:00
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
} else if (val > 0 && val > v->longestp) {
|
|
|
|
v->longestp = val;
|
2003-03-06 12:04:21 +03:00
|
|
|
fmtlen = iwidth(val);
|
2000-06-07 08:57:59 +04:00
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VUNSIGN:
|
|
|
|
if (uval > v->longestu) {
|
|
|
|
v->longestu = uval;
|
2003-03-06 12:04:21 +03:00
|
|
|
v->width = iwidth(uval);
|
2000-06-07 08:57:59 +04:00
|
|
|
}
|
|
|
|
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) {
|
|
|
|
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:
|
2003-03-06 12:04:21 +03:00
|
|
|
(void)printf(ofmt, width, GET(u_int64_t));
|
2000-06-07 08:57:59 +04:00
|
|
|
return;
|
1999-05-03 04:17:30 +04:00
|
|
|
case KPTR24:
|
2003-03-06 12:04:21 +03:00
|
|
|
(void)printf(ofmt, width, GET(u_int64_t) & 0xffffff);
|
|
|
|
return;
|
|
|
|
case INT32:
|
|
|
|
(void)printf(ofmt, width, GET(int32_t));
|
|
|
|
return;
|
|
|
|
case UINT32:
|
|
|
|
(void)printf(ofmt, width, CHK_INF127(GET(u_int32_t)));
|
2000-06-07 08:57:59 +04:00
|
|
|
return;
|
1999-04-16 17:34:32 +04:00
|
|
|
case SIGLIST:
|
|
|
|
{
|
|
|
|
sigset_t *s = (sigset_t *)(void *)bp;
|
|
|
|
size_t i;
|
2004-03-27 17:09:10 +03:00
|
|
|
#define SIGSETSIZE (sizeof(s->__bits) / sizeof(s->__bits[0]))
|
1999-04-16 17:34:32 +04:00
|
|
|
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 */
|
2003-03-06 12:04:21 +03:00
|
|
|
for (i = 0; buf[i] == '0'; i++)
|
|
|
|
continue;
|
1999-04-16 17:34:32 +04:00
|
|
|
|
|
|
|
if (buf[i] == '\0')
|
|
|
|
i--;
|
2003-03-06 12:04:21 +03:00
|
|
|
strprintorsetwidth(v, buf + i, mode);
|
|
|
|
#undef SIGSETSIZE
|
1999-04-16 17:34:32 +04:00
|
|
|
}
|
2003-03-06 12:04:21 +03:00
|
|
|
return;
|
Since kinfo_proc2 has many values that are 64-bit, ps needs to know
that they're 64-bit, and grab them out of memory appropriately. Otherwise,
big-endian systems get the wrong end of the 64-bit value and lose.
Keywords affected: inblk, majflt, minflt, msgrcv, msgsnd, nivcsw, nsigs,
nswap, nvcsw, and oublk.
2002-04-25 01:41:22 +04:00
|
|
|
case INT64:
|
2003-03-06 12:04:21 +03:00
|
|
|
(void)printf(ofmt, width, GET(int64_t));
|
Since kinfo_proc2 has many values that are 64-bit, ps needs to know
that they're 64-bit, and grab them out of memory appropriately. Otherwise,
big-endian systems get the wrong end of the 64-bit value and lose.
Keywords affected: inblk, majflt, minflt, msgrcv, msgsnd, nivcsw, nsigs,
nswap, nvcsw, and oublk.
2002-04-25 01:41:22 +04:00
|
|
|
return;
|
|
|
|
case UINT64:
|
2003-03-06 12:04:21 +03:00
|
|
|
(void)printf(ofmt, width, CHK_INF127(GET(u_int64_t)));
|
Since kinfo_proc2 has many values that are 64-bit, ps needs to know
that they're 64-bit, and grab them out of memory appropriately. Otherwise,
big-endian systems get the wrong end of the 64-bit value and lose.
Keywords affected: inblk, majflt, minflt, msgrcv, msgsnd, nivcsw, nsigs,
nswap, nvcsw, and oublk.
2002-04-25 01:41:22 +04:00
|
|
|
return;
|
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
|
|
|
}
|
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
|
2014-04-21 02:48:59 +04:00
|
|
|
pvar(void *arg, VARENT *ve, enum mode mode)
|
1994-05-09 07:31:07 +04:00
|
|
|
{
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2003-03-06 12:04:21 +03:00
|
|
|
if (v->flag & UAREA && !((struct kinfo_proc2 *)arg)->p_uvalid) {
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%*s", v->width, "-");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printval((char *)arg + v->off, v, mode);
|
1994-05-09 07:31:07 +04:00
|
|
|
}
|
2003-03-06 12:04:21 +03:00
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
putimeval(void *arg, VARENT *ve, enum mode mode)
|
2003-03-06 12:04:21 +03:00
|
|
|
{
|
|
|
|
VAR *v = ve->var;
|
|
|
|
struct kinfo_proc2 *k = arg;
|
|
|
|
ulong secs = *(uint32_t *)((char *)arg + v->off);
|
|
|
|
ulong usec = *(uint32_t *)((char *)arg + v->off + sizeof (uint32_t));
|
|
|
|
int fmtlen;
|
|
|
|
|
|
|
|
if (!k->p_uvalid) {
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%*s", v->width, "-");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == WIDTHMODE) {
|
2004-03-27 17:49:13 +03:00
|
|
|
if (secs == 0)
|
|
|
|
/* non-zero so fmtlen is calculated at least once */
|
2003-03-06 12:04:21 +03:00
|
|
|
secs = 1;
|
|
|
|
if (secs > v->longestu) {
|
|
|
|
v->longestu = secs;
|
|
|
|
if (secs <= 999)
|
|
|
|
/* sss.ssssss */
|
|
|
|
fmtlen = iwidth(secs) + 6 + 1;
|
|
|
|
else
|
|
|
|
/* hh:mm:ss.ss */
|
2004-03-27 15:59:25 +03:00
|
|
|
fmtlen = iwidth((secs + 1) / SECSPERHOUR)
|
2003-03-06 12:04:21 +03:00
|
|
|
+ 2 + 1 + 2 + 1 + 2 + 1;
|
|
|
|
if (fmtlen > v->width)
|
|
|
|
v->width = fmtlen;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (secs < 999)
|
|
|
|
(void)printf( "%*lu.%.6lu", v->width - 6 - 1, secs, usec);
|
|
|
|
else {
|
|
|
|
uint h, m;
|
|
|
|
usec += 5000;
|
|
|
|
if (usec >= 1000000) {
|
|
|
|
usec -= 1000000;
|
|
|
|
secs++;
|
|
|
|
}
|
2004-03-27 15:59:25 +03:00
|
|
|
m = secs / SECSPERMIN;
|
|
|
|
secs -= m * SECSPERMIN;
|
|
|
|
h = m / MINSPERHOUR;
|
|
|
|
m -= h * MINSPERHOUR;
|
2004-03-27 15:44:08 +03:00
|
|
|
(void)printf( "%*u:%.2u:%.2lu.%.2lu", v->width - 9, h, m, secs,
|
|
|
|
usec / 10000u );
|
2003-03-06 12:04:21 +03:00
|
|
|
}
|
|
|
|
}
|
2007-09-01 20:54:39 +04:00
|
|
|
|
|
|
|
void
|
2014-04-21 02:48:59 +04:00
|
|
|
lname(void *arg, VARENT *ve, enum mode mode)
|
2007-09-01 20:54:39 +04:00
|
|
|
{
|
|
|
|
struct kinfo_lwp *l;
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
l = arg;
|
|
|
|
v = ve->var;
|
2014-11-15 04:58:34 +03:00
|
|
|
if (l->l_name[0] != '\0') {
|
2007-09-01 20:54:39 +04:00
|
|
|
strprintorsetwidth(v, l->l_name, mode);
|
|
|
|
v->width = min(v->width, KI_LNAMELEN);
|
|
|
|
} else {
|
|
|
|
if (mode == PRINTMODE)
|
|
|
|
(void)printf("%-*s", v->width, "-");
|
|
|
|
}
|
|
|
|
}
|