1994-05-26 06:18:55 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1998-05-15 06:30:58 +00:00
|
|
|
#if 0
|
2002-02-03 14:43:04 +00:00
|
|
|
#ifndef lint
|
1998-05-15 06:30:58 +00:00
|
|
|
static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94";
|
1994-05-26 06:18:55 +00:00
|
|
|
#endif /* not lint */
|
2002-02-03 14:43:04 +00:00
|
|
|
#endif
|
2003-02-05 13:18:17 +00:00
|
|
|
|
2002-06-30 05:15:05 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 06:18:55 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2002-10-24 00:00:57 +00:00
|
|
|
#include <sys/mac.h>
|
1995-10-28 20:11:18 +00:00
|
|
|
#include <sys/user.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
#include <sys/sysctl.h>
|
2011-01-09 12:50:44 +00:00
|
|
|
#include <sys/vmmeter.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
2002-02-19 00:05:59 +00:00
|
|
|
#include <grp.h>
|
2001-03-03 01:46:58 +00:00
|
|
|
#include <langinfo.h>
|
2001-02-11 02:25:56 +00:00
|
|
|
#include <locale.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <nlist.h>
|
2002-02-19 00:05:59 +00:00
|
|
|
#include <pwd.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
#include <stddef.h>
|
2010-03-17 22:57:58 +00:00
|
|
|
#include <stdint.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-02-03 14:43:04 +00:00
|
|
|
#include <unistd.h>
|
1994-05-26 06:18:55 +00:00
|
|
|
#include <vis.h>
|
|
|
|
|
|
|
|
#include "ps.h"
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
#define COMMAND_WIDTH 16
|
|
|
|
#define ARGUMENTS_WIDTH 16
|
|
|
|
|
2002-09-13 07:13:33 +00:00
|
|
|
#define ps_pgtok(a) (((a) * getpagesize()) / 1024)
|
2002-02-03 14:43:04 +00:00
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
void
|
2002-02-02 06:48:10 +00:00
|
|
|
printheader(void)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
VAR *v;
|
|
|
|
struct varent *vent;
|
|
|
|
|
2004-06-23 23:48:09 +00:00
|
|
|
STAILQ_FOREACH(vent, &varlist, next_ve)
|
|
|
|
if (*vent->header != '\0')
|
2002-10-31 13:41:37 +00:00
|
|
|
break;
|
2004-06-23 23:48:09 +00:00
|
|
|
if (!vent)
|
2002-10-31 13:41:37 +00:00
|
|
|
return;
|
2004-06-23 23:48:09 +00:00
|
|
|
|
|
|
|
STAILQ_FOREACH(vent, &varlist, next_ve) {
|
1994-05-26 06:18:55 +00:00
|
|
|
v = vent->var;
|
|
|
|
if (v->flag & LJUST) {
|
2004-06-23 23:48:09 +00:00
|
|
|
if (STAILQ_NEXT(vent, next_ve) == NULL) /* last one */
|
2003-01-19 00:31:16 +00:00
|
|
|
(void)printf("%s", vent->header);
|
1994-05-26 06:18:55 +00:00
|
|
|
else
|
2003-01-19 00:31:16 +00:00
|
|
|
(void)printf("%-*s", v->width, vent->header);
|
1994-05-26 06:18:55 +00:00
|
|
|
} else
|
2003-01-19 00:31:16 +00:00
|
|
|
(void)printf("%*s", v->width, vent->header);
|
2004-06-23 23:48:09 +00:00
|
|
|
if (STAILQ_NEXT(vent, next_ve) != NULL)
|
1994-05-26 06:18:55 +00:00
|
|
|
(void)putchar(' ');
|
|
|
|
}
|
|
|
|
(void)putchar('\n');
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2002-06-06 20:21:47 +00:00
|
|
|
arguments(KINFO *k, VARENT *ve)
|
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *vis_args;
|
2002-06-06 20:21:47 +00:00
|
|
|
|
|
|
|
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
|
|
|
|
errx(1, "malloc failed");
|
|
|
|
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
|
2011-09-29 06:31:42 +00:00
|
|
|
|
|
|
|
if (STAILQ_NEXT(ve, next_ve) != NULL && strlen(vis_args) > ARGUMENTS_WIDTH)
|
|
|
|
vis_args[ARGUMENTS_WIDTH] = '\0';
|
|
|
|
|
|
|
|
return (vis_args);
|
2002-06-06 20:21:47 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2002-02-02 06:48:10 +00:00
|
|
|
command(KINFO *k, VARENT *ve)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *vis_args, *vis_env, *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
1996-10-21 07:30:26 +00:00
|
|
|
if (cflag) {
|
2004-06-23 23:48:09 +00:00
|
|
|
/* If it is the last field, then don't pad */
|
2007-10-26 08:00:41 +00:00
|
|
|
if (STAILQ_NEXT(ve, next_ve) == NULL) {
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%s%s%s%s",
|
|
|
|
k->ki_d.prefix ? k->ki_d.prefix : "",
|
|
|
|
k->ki_p->ki_comm,
|
|
|
|
(showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "",
|
|
|
|
(showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "");
|
2007-10-26 08:00:41 +00:00
|
|
|
} else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_comm);
|
|
|
|
|
|
|
|
return (str);
|
1996-10-21 07:30:26 +00:00
|
|
|
}
|
1994-05-26 06:18:55 +00:00
|
|
|
if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL)
|
2002-06-05 18:11:25 +00:00
|
|
|
errx(1, "malloc failed");
|
1994-05-26 06:18:55 +00:00
|
|
|
strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH);
|
|
|
|
|
2004-06-23 23:48:09 +00:00
|
|
|
if (STAILQ_NEXT(ve, next_ve) == NULL) {
|
1994-05-26 06:18:55 +00:00
|
|
|
/* last field */
|
2009-05-17 04:00:43 +00:00
|
|
|
|
|
|
|
if (k->ki_env) {
|
|
|
|
if ((vis_env = malloc(strlen(k->ki_env) * 4 + 1))
|
|
|
|
== NULL)
|
|
|
|
errx(1, "malloc failed");
|
|
|
|
strvis(vis_env, k->ki_env,
|
|
|
|
VIS_TAB | VIS_NL | VIS_NOSLASH);
|
|
|
|
} else
|
|
|
|
vis_env = NULL;
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%s%s%s%s",
|
|
|
|
k->ki_d.prefix ? k->ki_d.prefix : "",
|
|
|
|
vis_env ? vis_env : "",
|
|
|
|
vis_env ? " " : "",
|
|
|
|
vis_args);
|
|
|
|
|
2009-05-17 04:00:43 +00:00
|
|
|
if (vis_env != NULL)
|
|
|
|
free(vis_env);
|
2011-09-29 06:31:42 +00:00
|
|
|
free(vis_args);
|
|
|
|
} else {
|
2009-05-17 04:00:43 +00:00
|
|
|
/* ki_d.prefix & ki_env aren't shown for interim fields */
|
2011-09-29 06:31:42 +00:00
|
|
|
str = vis_args;
|
|
|
|
|
|
|
|
if (strlen(str) > COMMAND_WIDTH)
|
|
|
|
str[COMMAND_WIDTH] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2002-02-02 06:48:10 +00:00
|
|
|
ucomm(KINFO *k, VARENT *ve)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2007-10-26 08:00:41 +00:00
|
|
|
if (STAILQ_NEXT(ve, next_ve) == NULL) { /* last field, don't pad */
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%s%s%s%s",
|
|
|
|
k->ki_d.prefix ? k->ki_d.prefix : "",
|
|
|
|
k->ki_p->ki_comm,
|
|
|
|
(showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "",
|
|
|
|
(showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : "");
|
2009-02-26 18:01:07 +00:00
|
|
|
} else {
|
|
|
|
if (showthreads && k->ki_p->ki_numthreads > 1)
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%s/%s", k->ki_p->ki_comm, k->ki_p->ki_tdname);
|
2009-02-26 18:01:07 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_comm);
|
2009-02-26 18:01:07 +00:00
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
tdnam(KINFO *k, VARENT *ve __unused)
|
2007-10-26 08:00:41 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2007-10-26 08:00:41 +00:00
|
|
|
|
|
|
|
if (showthreads && k->ki_p->ki_numthreads > 1)
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_tdname);
|
2008-11-13 15:06:34 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(" ");
|
|
|
|
|
|
|
|
return (str);
|
2007-10-26 08:00:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
logname(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (*k->ki_p->ki_login == '\0')
|
|
|
|
return (NULL);
|
|
|
|
return (strdup(k->ki_p->ki_login));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
state(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2007-09-17 05:31:39 +00:00
|
|
|
int flag, tdflags;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *cp, *buf;
|
|
|
|
|
|
|
|
buf = malloc(16);
|
|
|
|
if (buf == NULL)
|
|
|
|
errx(1, "malloc failed");
|
1994-05-26 06:18:55 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
flag = k->ki_p->ki_flag;
|
2001-09-12 08:38:13 +00:00
|
|
|
tdflags = k->ki_p->ki_tdflags; /* XXXKSE */
|
1994-05-26 06:18:55 +00:00
|
|
|
cp = buf;
|
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
switch (k->ki_p->ki_stat) {
|
1994-05-26 06:18:55 +00:00
|
|
|
|
|
|
|
case SSTOP:
|
|
|
|
*cp = 'T';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SSLEEP:
|
2001-09-12 08:38:13 +00:00
|
|
|
if (tdflags & TDF_SINTR) /* interruptable (long) */
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
*cp = k->ki_p->ki_slptime >= MAXSLP ? 'I' : 'S';
|
1994-05-26 06:18:55 +00:00
|
|
|
else
|
|
|
|
*cp = 'D';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SRUN:
|
|
|
|
case SIDL:
|
|
|
|
*cp = 'R';
|
|
|
|
break;
|
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
case SWAIT:
|
|
|
|
*cp = 'W';
|
|
|
|
break;
|
|
|
|
|
2002-10-02 20:33:52 +00:00
|
|
|
case SLOCK:
|
|
|
|
*cp = 'L';
|
2000-09-07 01:33:02 +00:00
|
|
|
break;
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
case SZOMB:
|
|
|
|
*cp = 'Z';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
*cp = '?';
|
|
|
|
}
|
|
|
|
cp++;
|
2007-09-17 05:31:39 +00:00
|
|
|
if (!(flag & P_INMEM))
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = 'W';
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (k->ki_p->ki_nice < NZERO)
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = '<';
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
else if (k->ki_p->ki_nice > NZERO)
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = 'N';
|
|
|
|
if (flag & P_TRACED)
|
|
|
|
*cp++ = 'X';
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (flag & P_WEXIT && k->ki_p->ki_stat != SZOMB)
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = 'E';
|
|
|
|
if (flag & P_PPWAIT)
|
|
|
|
*cp++ = 'V';
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if ((flag & P_SYSTEM) || k->ki_p->ki_lock > 0)
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = 'L';
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (k->ki_p->ki_kiflag & KI_SLEADER)
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = 's';
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if ((flag & P_CONTROLT) && k->ki_p->ki_pgid == k->ki_p->ki_tpgid)
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp++ = '+';
|
This Implements the mumbled about "Jail" feature.
This is a seriously beefed up chroot kind of thing. The process
is jailed along the same lines as a chroot does it, but with
additional tough restrictions imposed on what the superuser can do.
For all I know, it is safe to hand over the root bit inside a
prison to the customer living in that prison, this is what
it was developed for in fact: "real virtual servers".
Each prison has an ip number associated with it, which all IP
communications will be coerced to use and each prison has its own
hostname.
Needless to say, you need more RAM this way, but the advantage is
that each customer can run their own particular version of apache
and not stomp on the toes of their neighbors.
It generally does what one would expect, but setting up a jail
still takes a little knowledge.
A few notes:
I have no scripts for setting up a jail, don't ask me for them.
The IP number should be an alias on one of the interfaces.
mount a /proc in each jail, it will make ps more useable.
/proc/<pid>/status tells the hostname of the prison for
jailed processes.
Quotas are only sensible if you have a mountpoint per prison.
There are no privisions for stopping resource-hogging.
Some "#ifdef INET" and similar may be missing (send patches!)
If somebody wants to take it from here and develop it into
more of a "virtual machine" they should be most welcome!
Tools, comments, patches & documentation most welcome.
Have fun...
Sponsored by: http://www.rndassociates.com/
Run for almost a year by: http://www.servetheweb.com/
1999-04-28 11:38:52 +00:00
|
|
|
if (flag & P_JAILED)
|
|
|
|
*cp++ = 'J';
|
1994-05-26 06:18:55 +00:00
|
|
|
*cp = '\0';
|
2011-09-29 06:31:42 +00:00
|
|
|
return (buf);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2004-06-23 11:56:57 +00:00
|
|
|
#define scalepri(x) ((x) - PZERO)
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
pri(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%d", scalepri(k->ki_p->ki_pri.pri_level));
|
|
|
|
return (str);
|
2004-06-23 11:56:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
upr(KINFO *k, VARENT *ve __unused)
|
2004-06-23 11:56:57 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2004-06-23 11:56:57 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%d", scalepri(k->ki_p->ki_pri.pri_user));
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
2004-06-23 11:56:57 +00:00
|
|
|
#undef scalepri
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
uname(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
return (strdup(user_from_uid(k->ki_p->ki_uid, 0)));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
egroupname(KINFO *k, VARENT *ve __unused)
|
2011-06-14 16:50:16 +00:00
|
|
|
{
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
return (strdup(group_from_gid(k->ki_p->ki_groups[0], 0)));
|
2011-06-14 16:50:16 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
rgroupname(KINFO *k, VARENT *ve __unused)
|
2002-06-06 20:42:16 +00:00
|
|
|
{
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
return (strdup(group_from_gid(k->ki_p->ki_rgid, 0)));
|
2002-06-06 20:42:16 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
runame(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
return (strdup(user_from_uid(k->ki_p->ki_ruid, 0)));
|
1997-04-29 05:26:05 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
tdev(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
dev = k->ki_p->ki_tdev;
|
1994-05-26 06:18:55 +00:00
|
|
|
if (dev == NODEV)
|
2011-10-30 15:21:27 +00:00
|
|
|
str = strdup("-");
|
2011-09-28 18:53:36 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%#jx", (uintmax_t)dev);
|
|
|
|
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
tname(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *ttname, *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
dev = k->ki_p->ki_tdev;
|
1994-05-26 06:18:55 +00:00
|
|
|
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
|
2011-10-30 15:21:27 +00:00
|
|
|
str = strdup("- ");
|
1994-05-26 06:18:55 +00:00
|
|
|
else {
|
1994-10-02 14:11:32 +00:00
|
|
|
if (strncmp(ttname, "tty", 3) == 0 ||
|
|
|
|
strncmp(ttname, "cua", 3) == 0)
|
1994-05-26 06:18:55 +00:00
|
|
|
ttname += 3;
|
2006-02-21 13:02:18 +00:00
|
|
|
if (strncmp(ttname, "pts/", 4) == 0)
|
|
|
|
ttname += 4;
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%s%c", ttname,
|
2003-04-14 19:51:36 +00:00
|
|
|
k->ki_p->ki_kiflag & KI_CTTY ? ' ' : '-');
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
longtname(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
dev_t dev;
|
2011-09-29 06:31:42 +00:00
|
|
|
const char *ttname;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
dev = k->ki_p->ki_tdev;
|
1994-05-26 06:18:55 +00:00
|
|
|
if (dev == NODEV || (ttname = devname(dev, S_IFCHR)) == NULL)
|
2011-10-30 15:21:27 +00:00
|
|
|
ttname = "-";
|
2011-09-29 06:31:42 +00:00
|
|
|
|
|
|
|
return (strdup(ttname));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
started(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
1998-06-28 18:19:13 +00:00
|
|
|
time_t then;
|
1994-05-26 06:18:55 +00:00
|
|
|
struct tm *tp;
|
2003-04-14 19:51:36 +00:00
|
|
|
static int use_ampm = -1;
|
2011-09-29 06:31:42 +00:00
|
|
|
size_t buflen = 100;
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
buf = malloc(buflen);
|
|
|
|
if (buf == NULL)
|
|
|
|
errx(1, "malloc failed");
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (!k->ki_valid)
|
|
|
|
return (NULL);
|
2001-03-03 01:46:58 +00:00
|
|
|
if (use_ampm < 0)
|
|
|
|
use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0');
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
then = k->ki_p->ki_start.tv_sec;
|
1998-06-28 18:19:13 +00:00
|
|
|
tp = localtime(&then);
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (now - k->ki_p->ki_start.tv_sec < 24 * 3600) {
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)strftime(buf, buflen,
|
2003-04-14 19:51:36 +00:00
|
|
|
use_ampm ? "%l:%M%p" : "%k:%M ", tp);
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
} else if (now - k->ki_p->ki_start.tv_sec < 7 * 86400) {
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)strftime(buf, buflen,
|
2003-04-14 19:51:36 +00:00
|
|
|
use_ampm ? "%a%I%p" : "%a%H ", tp);
|
1994-05-26 06:18:55 +00:00
|
|
|
} else
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)strftime(buf, buflen, "%e%b%y", tp);
|
|
|
|
return (buf);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
lstarted(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
1998-06-28 18:19:13 +00:00
|
|
|
time_t then;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *buf;
|
|
|
|
size_t buflen = 100;
|
|
|
|
|
|
|
|
buf = malloc(buflen);
|
|
|
|
if (buf == NULL)
|
|
|
|
errx(1, "malloc failed");
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (!k->ki_valid)
|
|
|
|
return (NULL);
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
then = k->ki_p->ki_start.tv_sec;
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)strftime(buf, buflen, "%c", localtime(&then));
|
|
|
|
return (buf);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
lockname(KINFO *k, VARENT *ve __unused)
|
2000-11-29 21:09:21 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2000-11-29 21:09:21 +00:00
|
|
|
|
2002-10-02 20:33:52 +00:00
|
|
|
if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) {
|
|
|
|
if (k->ki_p->ki_lockname[0] != 0)
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_lockname);
|
2000-11-29 21:09:21 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup("???");
|
2000-11-29 21:09:21 +00:00
|
|
|
} else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
return (str);
|
2000-11-29 21:09:21 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
wchan(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2002-02-21 18:27:16 +00:00
|
|
|
if (k->ki_p->ki_wchan) {
|
|
|
|
if (k->ki_p->ki_wmesg[0] != 0)
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_wmesg);
|
2002-02-21 18:27:16 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%lx", (long)k->ki_p->ki_wchan);
|
2003-04-14 19:51:36 +00:00
|
|
|
} else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
return (str);
|
2002-02-21 18:27:16 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
nwchan(KINFO *k, VARENT *ve __unused)
|
2003-08-13 07:35:07 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2003-08-13 07:35:07 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (k->ki_p->ki_wchan)
|
|
|
|
asprintf(&str, "%0lx", (long)k->ki_p->ki_wchan);
|
|
|
|
else
|
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
return (str);
|
2003-08-13 07:35:07 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
mwchan(KINFO *k, VARENT *ve __unused)
|
2002-02-21 18:27:16 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2002-02-21 18:27:16 +00:00
|
|
|
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
if (k->ki_p->ki_wchan) {
|
|
|
|
if (k->ki_p->ki_wmesg[0] != 0)
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_wmesg);
|
1994-05-26 06:18:55 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%lx", (long)k->ki_p->ki_wchan);
|
2002-10-02 20:33:52 +00:00
|
|
|
} else if (k->ki_p->ki_kiflag & KI_LOCKBLOCK) {
|
|
|
|
if (k->ki_p->ki_lockname[0]) {
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup(k->ki_p->ki_lockname);
|
2003-04-14 19:51:36 +00:00
|
|
|
} else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = strdup("???");
|
2003-04-14 19:51:36 +00:00
|
|
|
} else
|
2011-09-29 06:31:42 +00:00
|
|
|
str = NULL;
|
|
|
|
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
vsize(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%lu", (u_long)(k->ki_p->ki_size / 1024));
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
static char *
|
2012-01-17 22:17:10 +00:00
|
|
|
printtime(KINFO *k, VARENT *ve __unused, long secs, long psecs)
|
2011-03-17 11:25:32 +00:00
|
|
|
/* psecs is "parts" of a second. first micro, then centi */
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2003-04-14 19:51:36 +00:00
|
|
|
static char decimal_point;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2003-04-14 19:51:36 +00:00
|
|
|
if (decimal_point == '\0')
|
2001-02-11 02:25:56 +00:00
|
|
|
decimal_point = localeconv()->decimal_point[0];
|
2004-06-21 16:53:11 +00:00
|
|
|
if (!k->ki_valid) {
|
1998-05-31 12:09:50 +00:00
|
|
|
secs = 0;
|
|
|
|
psecs = 0;
|
1994-05-26 06:18:55 +00:00
|
|
|
} else {
|
2011-03-17 11:25:32 +00:00
|
|
|
/* round and scale to 100's */
|
1998-05-31 12:09:50 +00:00
|
|
|
psecs = (psecs + 5000) / 10000;
|
|
|
|
secs += psecs / 100;
|
|
|
|
psecs = psecs % 100;
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%ld:%02ld%c%02ld",
|
2003-04-14 19:51:36 +00:00
|
|
|
secs / 60, secs % 60, decimal_point, psecs);
|
2011-09-29 06:31:42 +00:00
|
|
|
return (str);
|
2011-03-24 20:15:42 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2011-03-17 11:25:32 +00:00
|
|
|
cputime(KINFO *k, VARENT *ve)
|
|
|
|
{
|
|
|
|
long secs, psecs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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->ki_p->ki_runtime / 1000000;
|
|
|
|
psecs = k->ki_p->ki_runtime % 1000000;
|
|
|
|
if (sumrusage) {
|
|
|
|
secs += k->ki_p->ki_childtime.tv_sec;
|
|
|
|
psecs += k->ki_p->ki_childtime.tv_usec;
|
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
return (printtime(k, ve, secs, psecs));
|
2011-03-17 11:25:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2011-03-17 11:25:32 +00:00
|
|
|
systime(KINFO *k, VARENT *ve)
|
|
|
|
{
|
|
|
|
long secs, psecs;
|
|
|
|
|
|
|
|
secs = k->ki_p->ki_rusage.ru_stime.tv_sec;
|
|
|
|
psecs = k->ki_p->ki_rusage.ru_stime.tv_usec;
|
|
|
|
if (sumrusage) {
|
|
|
|
secs += k->ki_p->ki_childstime.tv_sec;
|
|
|
|
psecs += k->ki_p->ki_childstime.tv_usec;
|
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
return (printtime(k, ve, secs, psecs));
|
2011-03-17 11:25:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2011-03-17 11:25:32 +00:00
|
|
|
usertime(KINFO *k, VARENT *ve)
|
|
|
|
{
|
|
|
|
long secs, psecs;
|
|
|
|
|
|
|
|
secs = k->ki_p->ki_rusage.ru_utime.tv_sec;
|
|
|
|
psecs = k->ki_p->ki_rusage.ru_utime.tv_usec;
|
|
|
|
if (sumrusage) {
|
|
|
|
secs += k->ki_p->ki_childutime.tv_sec;
|
|
|
|
psecs += k->ki_p->ki_childutime.tv_usec;
|
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
return (printtime(k, ve, secs, psecs));
|
2011-03-17 11:25:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
elapsed(KINFO *k, VARENT *ve __unused)
|
2002-06-06 21:18:37 +00:00
|
|
|
{
|
2003-04-14 19:51:36 +00:00
|
|
|
time_t val;
|
|
|
|
int days, hours, mins, secs;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2002-06-06 21:18:37 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (!k->ki_valid)
|
|
|
|
return (NULL);
|
2003-04-14 19:51:36 +00:00
|
|
|
val = now - k->ki_p->ki_start.tv_sec;
|
|
|
|
days = val / (24 * 60 * 60);
|
|
|
|
val %= 24 * 60 * 60;
|
|
|
|
hours = val / (60 * 60);
|
|
|
|
val %= 60 * 60;
|
|
|
|
mins = val / 60;
|
|
|
|
secs = val % 60;
|
|
|
|
if (days != 0)
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%3d-%02d:%02d:%02d", days, hours, mins, secs);
|
2003-04-14 19:51:36 +00:00
|
|
|
else if (hours != 0)
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%02d:%02d:%02d", hours, mins, secs);
|
2003-04-14 19:51:36 +00:00
|
|
|
else
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%02d:%02d", mins, secs);
|
|
|
|
|
|
|
|
return (str);
|
2002-06-06 21:18:37 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
elapseds(KINFO *k, VARENT *ve __unused)
|
2010-03-17 22:57:58 +00:00
|
|
|
{
|
|
|
|
time_t val;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2010-03-17 22:57:58 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (!k->ki_valid)
|
|
|
|
return (NULL);
|
2010-03-17 22:57:58 +00:00
|
|
|
val = now - k->ki_p->ki_start.tv_sec;
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%jd", (intmax_t)val);
|
|
|
|
return (str);
|
2010-03-17 22:57:58 +00:00
|
|
|
}
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
double
|
2002-02-03 14:43:04 +00:00
|
|
|
getpcpu(const KINFO *k)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
static int failure;
|
|
|
|
|
|
|
|
if (!nlistread)
|
|
|
|
failure = donlist();
|
|
|
|
if (failure)
|
|
|
|
return (0.0);
|
|
|
|
|
|
|
|
#define fxtofl(fixpt) ((double)(fixpt) / fscale)
|
|
|
|
|
|
|
|
/* XXX - I don't like this */
|
2007-09-17 05:31:39 +00:00
|
|
|
if (k->ki_p->ki_swtime == 0 || (k->ki_p->ki_flag & P_INMEM) == 0)
|
1994-05-26 06:18:55 +00:00
|
|
|
return (0.0);
|
|
|
|
if (rawcpu)
|
Change the proc information returned from the kernel so that it
no longer contains kernel specific data structures, but rather
only scalar values and structures that are already part of the
kernel/user interface, specifically rusage and rtprio. It no
longer contains proc, session, pcred, ucred, procsig, vmspace,
pstats, mtx, sigiolst, klist, callout, pasleep, or mdproc. If
any of these changed in size, ps, w, fstat, gcore, systat, and
top would all stop working. The new structure has over 200 bytes
of unassigned space for future values to be added, yet is nearly
100 bytes smaller per entry than the structure that it replaced.
2000-12-12 07:25:57 +00:00
|
|
|
return (100.0 * fxtofl(k->ki_p->ki_pctcpu));
|
|
|
|
return (100.0 * fxtofl(k->ki_p->ki_pctcpu) /
|
|
|
|
(1.0 - exp(k->ki_p->ki_swtime * log(fxtofl(ccpu)))));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
pcpu(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%.1f", getpcpu(k));
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-03 14:43:04 +00:00
|
|
|
static double
|
2002-02-02 06:48:10 +00:00
|
|
|
getpmem(KINFO *k)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
static int failure;
|
|
|
|
double fracmem;
|
|
|
|
|
|
|
|
if (!nlistread)
|
|
|
|
failure = donlist();
|
|
|
|
if (failure)
|
|
|
|
return (0.0);
|
|
|
|
|
2007-09-17 05:31:39 +00:00
|
|
|
if ((k->ki_p->ki_flag & P_INMEM) == 0)
|
1994-05-26 06:18:55 +00:00
|
|
|
return (0.0);
|
|
|
|
/* XXX want pmap ptpages, segtab, etc. (per architecture) */
|
|
|
|
/* XXX don't have info about shared */
|
2003-04-14 19:51:36 +00:00
|
|
|
fracmem = ((float)k->ki_p->ki_rssize) / mempages;
|
1994-05-26 06:18:55 +00:00
|
|
|
return (100.0 * fracmem);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
pmem(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%.1f", getpmem(k));
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
pagein(KINFO *k, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%ld", k->ki_valid ? k->ki_p->ki_rusage.ru_majflt : 0);
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2002-02-03 14:43:04 +00:00
|
|
|
/* ARGSUSED */
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
maxrss(KINFO *k __unused, VARENT *ve __unused)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
|
1997-08-03 08:25:01 +00:00
|
|
|
/* XXX not yet */
|
2011-09-29 06:31:42 +00:00
|
|
|
return (NULL);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
priorityr(KINFO *k, VARENT *ve __unused)
|
1998-05-25 05:07:18 +00:00
|
|
|
{
|
2002-02-03 14:43:04 +00:00
|
|
|
struct priority *lpri;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *str;
|
2001-02-12 00:21:38 +00:00
|
|
|
unsigned class, level;
|
2004-03-28 02:13:31 +00:00
|
|
|
|
|
|
|
lpri = &k->ki_p->ki_pri;
|
2002-02-03 14:43:04 +00:00
|
|
|
class = lpri->pri_class;
|
|
|
|
level = lpri->pri_level;
|
2001-02-12 00:21:38 +00:00
|
|
|
switch (class) {
|
2004-06-27 23:59:38 +00:00
|
|
|
case PRI_ITHD:
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "intr:%u", level);
|
2004-06-27 23:59:38 +00:00
|
|
|
break;
|
2001-02-12 00:21:38 +00:00
|
|
|
case PRI_REALTIME:
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "real:%u", level);
|
1998-05-25 05:07:18 +00:00
|
|
|
break;
|
2001-02-12 00:21:38 +00:00
|
|
|
case PRI_TIMESHARE:
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "normal");
|
1998-05-25 05:07:18 +00:00
|
|
|
break;
|
2001-02-12 00:21:38 +00:00
|
|
|
case PRI_IDLE:
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "idle:%u", level);
|
1998-05-25 05:07:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-09-29 06:31:42 +00:00
|
|
|
asprintf(&str, "%u:%u", class, level);
|
1998-05-25 05:07:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
return (str);
|
1998-05-25 05:07:18 +00:00
|
|
|
}
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
/*
|
|
|
|
* Generic output routines. Print fields from various prototype
|
|
|
|
* structures.
|
|
|
|
*/
|
2011-09-29 06:31:42 +00:00
|
|
|
static char *
|
2002-07-07 21:45:59 +00:00
|
|
|
printval(void *bp, VAR *v)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
static char ofmt[32] = "%";
|
2002-06-05 01:02:13 +00:00
|
|
|
const char *fcp;
|
2011-09-29 06:31:42 +00:00
|
|
|
char *cp, *str;
|
1994-05-26 06:18:55 +00:00
|
|
|
|
|
|
|
cp = ofmt + 1;
|
|
|
|
fcp = v->fmt;
|
1995-03-19 13:29:28 +00:00
|
|
|
while ((*cp++ = *fcp++));
|
1994-05-26 06:18:55 +00:00
|
|
|
|
2003-04-12 10:39:56 +00:00
|
|
|
#define CHKINF127(n) (((n) > 127) && (v->flag & INF127) ? 127 : (n))
|
|
|
|
|
1994-05-26 06:18:55 +00:00
|
|
|
switch (v->type) {
|
|
|
|
case CHAR:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(char *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
|
|
|
case UCHAR:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(u_char *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
|
|
|
case SHORT:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(short *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
|
|
|
case USHORT:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(u_short *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
1998-09-14 08:32:20 +00:00
|
|
|
case INT:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(int *)bp);
|
1998-09-14 08:32:20 +00:00
|
|
|
break;
|
|
|
|
case UINT:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, CHKINF127(*(u_int *)bp));
|
1998-09-14 08:32:20 +00:00
|
|
|
break;
|
1994-05-26 06:18:55 +00:00
|
|
|
case LONG:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(long *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
|
|
|
case ULONG:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(u_long *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
|
|
|
case KPTR:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, *(u_long *)bp);
|
1994-05-26 06:18:55 +00:00
|
|
|
break;
|
2002-09-17 17:13:52 +00:00
|
|
|
case PGTOK:
|
2011-09-29 06:31:42 +00:00
|
|
|
(void)asprintf(&str, ofmt, ps_pgtok(*(u_long *)bp));
|
2002-09-17 02:52:44 +00:00
|
|
|
break;
|
1994-05-26 06:18:55 +00:00
|
|
|
default:
|
|
|
|
errx(1, "unknown type %d", v->type);
|
|
|
|
}
|
2011-09-29 06:31:42 +00:00
|
|
|
|
|
|
|
return (str);
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2002-02-02 06:48:10 +00:00
|
|
|
kvar(KINFO *k, VARENT *ve)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2011-09-29 06:31:42 +00:00
|
|
|
return (printval((char *)((char *)k->ki_p + v->off), v));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2002-02-02 06:48:10 +00:00
|
|
|
rvar(KINFO *k, VARENT *ve)
|
1994-05-26 06:18:55 +00:00
|
|
|
{
|
|
|
|
VAR *v;
|
|
|
|
|
|
|
|
v = ve->var;
|
2011-09-29 06:31:42 +00:00
|
|
|
if (!k->ki_valid)
|
|
|
|
return (NULL);
|
|
|
|
return (printval((char *)((char *)(&k->ki_p->ki_rusage) + v->off), v));
|
1994-05-26 06:18:55 +00:00
|
|
|
}
|
2001-11-26 22:21:15 +00:00
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
emulname(KINFO *k, VARENT *ve __unused)
|
2004-06-20 23:40:54 +00:00
|
|
|
{
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
if (k->ki_p->ki_emul == NULL)
|
|
|
|
return (NULL);
|
|
|
|
return (strdup(k->ki_p->ki_emul));
|
2004-06-20 23:40:54 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
label(KINFO *k, VARENT *ve __unused)
|
2001-11-26 22:21:15 +00:00
|
|
|
{
|
2002-10-24 00:00:57 +00:00
|
|
|
char *string;
|
2003-01-18 03:31:30 +00:00
|
|
|
mac_t proclabel;
|
2002-10-24 00:00:57 +00:00
|
|
|
int error;
|
2001-11-26 22:21:15 +00:00
|
|
|
|
2002-10-24 00:00:57 +00:00
|
|
|
string = NULL;
|
2003-01-18 03:31:30 +00:00
|
|
|
if (mac_prepare_process_label(&proclabel) == -1) {
|
2004-07-20 05:52:00 +00:00
|
|
|
warn("mac_prepare_process_label");
|
2002-10-24 00:00:57 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2003-01-18 03:31:30 +00:00
|
|
|
error = mac_get_pid(k->ki_p->ki_pid, proclabel);
|
2002-10-24 00:00:57 +00:00
|
|
|
if (error == 0) {
|
2003-01-18 03:31:30 +00:00
|
|
|
if (mac_to_text(proclabel, &string) == -1)
|
2002-10-24 00:00:57 +00:00
|
|
|
string = NULL;
|
|
|
|
}
|
2003-01-18 03:31:30 +00:00
|
|
|
mac_free(proclabel);
|
2002-10-24 00:00:57 +00:00
|
|
|
out:
|
2011-09-29 06:31:42 +00:00
|
|
|
return (string);
|
2002-10-24 00:00:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:31:42 +00:00
|
|
|
char *
|
2012-01-17 22:17:10 +00:00
|
|
|
loginclass(KINFO *k, VARENT *ve __unused)
|
2011-03-05 14:41:49 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't display login class for system processes;
|
|
|
|
* login classes are used for resource limits,
|
|
|
|
* and limits don't apply to system processes.
|
|
|
|
*/
|
|
|
|
if (k->ki_p->ki_flag & P_SYSTEM) {
|
2011-09-29 06:31:42 +00:00
|
|
|
return (strdup("-"));
|
2002-10-24 00:00:57 +00:00
|
|
|
}
|
2011-03-24 17:20:24 +00:00
|
|
|
s = k->ki_p->ki_loginclass;
|
|
|
|
if (s == NULL)
|
2011-09-29 06:31:42 +00:00
|
|
|
return (NULL);
|
|
|
|
return (strdup(s));
|
2011-03-24 20:15:42 +00:00
|
|
|
}
|