summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrafan <rafan@FreeBSD.org>2007-04-17 03:12:39 +0000
committerrafan <rafan@FreeBSD.org>2007-04-17 03:12:39 +0000
commit3306a8a299e3b5170060a4f3551d52d929086ff2 (patch)
tree4e535601ecfa94915c8c4ffddd1c949ea023e3c7
parentee0894c663d96e1c56d3709ca4bcc97931f9c57c (diff)
downloadFreeBSD-src-3306a8a299e3b5170060a4f3551d52d929086ff2.zip
FreeBSD-src-3306a8a299e3b5170060a4f3551d52d929086ff2.tar.gz
- Add a new 'j' switch and runtime option to toggle display jail id for
each process. - While I'm here, keep help message sorted by keys PR: 98489, 98975 Submitted by: clsung Approved by: delphij (mentor) MFC after: 2 weeks
-rw-r--r--contrib/top/commands.c3
-rw-r--r--contrib/top/machine.h1
-rw-r--r--contrib/top/top.X19
-rw-r--r--contrib/top/top.c23
-rw-r--r--usr.bin/top/machine.c57
5 files changed, 85 insertions, 18 deletions
diff --git a/contrib/top/commands.c b/contrib/top/commands.c
index 200f0cc..58e00fb 100644
--- a/contrib/top/commands.c
+++ b/contrib/top/commands.c
@@ -71,8 +71,9 @@ sophisticated enough to handle those commands gracefully.\n\n", stdout);
C - toggle the displaying of weighted CPU percentage\n\
d - change number of displays to show\n\
e - list errors generated by last \"kill\" or \"renice\" command\n\
-i or I - toggle the displaying of idle processes\n\
H - toggle the displaying of threads\n\
+i or I - toggle the displaying of idle processes\n\
+j - toggle the displaying of jail id\n\
k - kill processes; send a signal to a list of processes\n\
m - toggle the display between 'cpu' and 'io' modes\n\
n or # - change number of processes to display\n", stdout);
diff --git a/contrib/top/machine.h b/contrib/top/machine.h
index 17e48cd..822c9d6 100644
--- a/contrib/top/machine.h
+++ b/contrib/top/machine.h
@@ -62,6 +62,7 @@ struct process_select
int thread; /* show threads */
int uid; /* only this uid (unless uid == -1) */
int wcpu; /* show weighted cpu */
+ int jail; /* show jail id */
char *command; /* only this command (unless == NULL) */
};
diff --git a/contrib/top/top.X b/contrib/top/top.X
index 304ee91..49b6c20 100644
--- a/contrib/top/top.X
+++ b/contrib/top/top.X
@@ -10,7 +10,7 @@ top \- display and update information about the top cpu processes
.SH SYNOPSIS
.B top
[
-.B \-abCHIinqStuv
+.B \-abCHIijnqStuv
] [
.BI \-d count
] [
@@ -102,6 +102,11 @@ intelligent terminal.
Do not display idle processes.
By default, top displays both active and idle processes.
.TP
+.B \-j
+Display the
+.IR jail (8)
+id.
+.TP
.B \-t
Do not display the
.I top
@@ -283,6 +288,11 @@ command.
.BR I )
Toggle the display of idle processes.
.TP
+.B j
+Toggle the display of
+.IR jail (8)
+id.
+.TP
.B t
Toggle the display of the
.I top
@@ -308,8 +318,11 @@ It also includes information about physical and virtual memory allocation.
The remainder of the screen displays information about individual
processes. This display is similar in spirit to
.IR ps (1)
-but it is not exactly the same. PID is the process id, USERNAME is the name
-of the process's owner (if
+but it is not exactly the same. PID is the process id,
+JID, when displayed, is the
+.IR jail (8)
+ID corresponding to the process,
+USERNAME is the name of the process's owner (if
.B \-u
is specified, a UID column will be substituted for USERNAME),
PRI is the current priority of the process,
diff --git a/contrib/top/top.c b/contrib/top/top.c
index 970d143..fbadb69 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -195,9 +195,9 @@ char *argv[];
fd_set readfds;
#ifdef ORDER
- static char command_chars[] = "\f qh?en#sdkriIutHmSCao";
+ static char command_chars[] = "\f qh?en#sdkriIutHmSCajo";
#else
- static char command_chars[] = "\f qh?en#sdkriIutHmSCa";
+ static char command_chars[] = "\f qh?en#sdkriIutHmSCaj";
#endif
/* these defines enumerate the "strchr"s of the commands in command_chars */
#define CMD_redraw 0
@@ -222,8 +222,9 @@ char *argv[];
#define CMD_viewsys 18
#define CMD_wcputog 19
#define CMD_showargs 20
+#define CMD_jidtog 21
#ifdef ORDER
-#define CMD_order 21
+#define CMD_order 22
#endif
/* set the buffer for stdout */
@@ -255,6 +256,7 @@ char *argv[];
ps.uid = -1;
ps.thread = No;
ps.wcpu = 1;
+ ps.jail = No;
ps.command = NULL;
/* get preset options from the environment */
@@ -280,7 +282,7 @@ char *argv[];
optind = 1;
}
- while ((i = getopt(ac, av, "CSIHabinquvs:d:U:m:o:t")) != EOF)
+ while ((i = getopt(ac, av, "CSIHabijnquvs:d:U:m:o:t")) != EOF)
{
switch(i)
{
@@ -401,6 +403,10 @@ char *argv[];
ps.thread = !ps.thread;
break;
+ case 'j':
+ ps.jail = !ps.jail;
+ break;
+
default:
fprintf(stderr,
"Top version %s\n"
@@ -1055,6 +1061,15 @@ restart:
}
break;
#endif
+ case CMD_jidtog:
+ ps.jail = !ps.jail;
+ new_message(MT_standout | MT_delayed,
+ " %sisplaying jail id.",
+ ps.jail ? "D" : "Not d");
+ header_text = format_header(uname_field);
+ reset_display();
+ putchar('\r');
+ break;
default:
new_message(MT_standout, " BAD CASE IN SWITCH!");
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 7d973b8..083055f 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -95,26 +95,26 @@ struct handle {
*/
static char io_header[] =
- " PID %-*.*s VCSW IVCSW READ WRITE FAULT TOTAL PERCENT COMMAND";
+ " PID%s %-*.*s VCSW IVCSW READ WRITE FAULT TOTAL PERCENT COMMAND";
#define io_Proc_format \
- "%5d %-*.*s %6ld %6ld %6ld %6ld %6ld %6ld %6.2f%% %.*s"
+ "%5d%s %-*.*s %6ld %6ld %6ld %6ld %6ld %6ld %6.2f%% %.*s"
static char smp_header_thr[] =
- " PID %-*.*s THR PRI NICE SIZE RES STATE C TIME %6s COMMAND";
+ " PID%s %-*.*s THR PRI NICE SIZE RES STATE C TIME %6s COMMAND";
static char smp_header[] =
- " PID %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND";
+ " PID%s %-*.*s " "PRI NICE SIZE RES STATE C TIME %6s COMMAND";
#define smp_Proc_format \
- "%5d %-*.*s %s%3d %4s%7s %6s %-6.6s %1x%7s %5.2f%% %.*s"
+ "%5d%s %-*.*s %s%3d %4s%7s %6s %-6.6s %1x%7s %5.2f%% %.*s"
static char up_header_thr[] =
- " PID %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND";
+ " PID%s %-*.*s THR PRI NICE SIZE RES STATE TIME %6s COMMAND";
static char up_header[] =
- " PID %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND";
+ " PID%s %-*.*s " "PRI NICE SIZE RES STATE TIME %6s COMMAND";
#define up_Proc_format \
- "%5d %-*.*s %s%3d %4s%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s"
+ "%5d%s %-*.*s %s%3d %4s%7s %6s %-6.6s%.0d%7s %5.2f%% %.*s"
/* process state names for the "STATE" column of the display */
@@ -211,10 +211,12 @@ long percentages();
*/
char *ordernames[] = {
"cpu", "size", "res", "time", "pri", "threads",
- "total", "read", "write", "fault", "vcsw", "ivcsw", NULL
+ "total", "read", "write", "fault", "vcsw", "ivcsw",
+ "jid", NULL
};
#endif
+static int compare_jid(const void *a, const void *b);
static int compare_pid(const void *a, const void *b);
static const char *format_nice(const struct kinfo_proc *pp);
static void getsysctl(const char *name, void *ptr, size_t len);
@@ -300,12 +302,14 @@ format_header(char *uname_field)
(ps.thread ? smp_header : smp_header_thr) :
(ps.thread ? up_header : up_header_thr);
snprintf(Header, sizeof(Header), prehead,
+ ps.jail ? " JID" : "",
namelength, namelength, uname_field,
ps.wcpu ? "WCPU" : "CPU");
break;
case DISP_IO:
prehead = io_header;
snprintf(Header, sizeof(Header), prehead,
+ ps.jail ? " JID" : "",
namelength, namelength, uname_field);
break;
}
@@ -661,7 +665,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags)
int state;
struct rusage ru, *rup;
long p_tot, s_tot;
- char *proc_fmt, thr_buf[6];
+ char *proc_fmt, thr_buf[6], jid_buf[6];
char *cmdbuf = NULL;
char **args;
@@ -785,6 +789,12 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags)
free(argbuf);
}
+ if (ps.jail == 0)
+ jid_buf[0] = '\0';
+ else
+ snprintf(jid_buf, sizeof(jid_buf), " %*d",
+ sizeof(jid_buf) - 3, pp->ki_jid);
+
if (displaymode == DISP_IO) {
oldp = get_old_proc(pp);
if (oldp != NULL) {
@@ -804,6 +814,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags)
sprintf(fmt, io_Proc_format,
pp->ki_pid,
+ jid_buf,
namelength, namelength, (*get_userid)(pp->ki_ruid),
rup->ru_nvcsw,
rup->ru_nivcsw,
@@ -831,6 +842,7 @@ format_next_process(caddr_t handle, char *(*get_userid)(int), int flags)
sprintf(fmt, proc_fmt,
pp->ki_pid,
+ jid_buf,
namelength, namelength, (*get_userid)(pp->ki_ruid),
thr_buf,
pp->ki_pri.pri_level - PZERO,
@@ -985,6 +997,12 @@ static int sorted_state[] = {
return (diff > 0 ? 1 : -1); \
} while (0)
+#define ORDERKEY_JID(a, b) do { \
+ int diff = (int)(b)->ki_jid - (int)(a)->ki_jid; \
+ if (diff != 0) \
+ return (diff > 0 ? 1 : -1); \
+} while (0)
+
/* compare_cpu - the comparison function for sorting by cpu percentage */
int
@@ -1032,6 +1050,7 @@ int (*compares[])() = {
compare_iofault,
compare_vcsw,
compare_ivcsw,
+ compare_jid,
NULL
};
@@ -1124,6 +1143,24 @@ compare_threads(void *arg1, void *arg2)
return (0);
}
+
+/* compare_jid - the comparison function for sorting by jid */
+static int
+compare_jid(const void *arg1, const void *arg2)
+{
+ struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
+ struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+
+ ORDERKEY_JID(p1, p2);
+ ORDERKEY_PCTCPU(p1, p2);
+ ORDERKEY_CPTICKS(p1, p2);
+ ORDERKEY_STATE(p1, p2);
+ ORDERKEY_PRIO(p1, p2);
+ ORDERKEY_RSSIZE(p1, p2);
+ ORDERKEY_MEM(p1, p2);
+
+ return (0);
+}
#endif /* ORDER */
/* assorted comparison functions for sorting by i/o */
OpenPOWER on IntegriCloud