summaryrefslogtreecommitdiffstats
path: root/contrib/top
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2014-05-02 23:30:39 +0000
committerbdrewery <bdrewery@FreeBSD.org>2014-05-02 23:30:39 +0000
commit1042af2b8ec8c05226f9f2c66b1c8faa2b33feb3 (patch)
tree1be93af025ad8a4895637f23b4ea30cad0f145da /contrib/top
parented48e9a0db7699d2d1249014920957127f258657 (diff)
downloadFreeBSD-src-1042af2b8ec8c05226f9f2c66b1c8faa2b33feb3.zip
FreeBSD-src-1042af2b8ec8c05226f9f2c66b1c8faa2b33feb3.tar.gz
Add -J command/flag to filter by jail name/jid. This will automatically
display the JID as well (the -j command/flag). 0 displays host. + displays all. MFC after: 2 weeks Relnotes: yes
Diffstat (limited to 'contrib/top')
-rw-r--r--contrib/top/machine.h1
-rw-r--r--contrib/top/top.X23
-rw-r--r--contrib/top/top.c61
3 files changed, 80 insertions, 5 deletions
diff --git a/contrib/top/machine.h b/contrib/top/machine.h
index 699c755..41da600 100644
--- a/contrib/top/machine.h
+++ b/contrib/top/machine.h
@@ -66,6 +66,7 @@ struct process_select
int thread; /* show threads */
int uid; /* only this uid (unless uid == -1) */
int wcpu; /* show weighted cpu */
+ int jid; /* only this jid (unless jid == -1) */
int jail; /* show jail ID */
int kidle; /* show per-CPU idle threads */
char *command; /* only this command (unless == NULL) */
diff --git a/contrib/top/top.X b/contrib/top/top.X
index 9c54f85..15cf2dc 100644
--- a/contrib/top/top.X
+++ b/contrib/top/top.X
@@ -20,6 +20,8 @@ top \- display and update information about the top cpu processes
] [
.BI \-s time
] [
+.BI \-J jail
+] [
.BI \-U username
] [
.I number
@@ -171,6 +173,21 @@ values are \*(lqcpu\*(rq, \*(lqsize\*(rq, \*(lqres\*(rq, and \*(lqtime\*(rq,
but may vary on different operating systems. Note that
not all operating systems support this option.
.TP
+.BI \-J jail
+Show only those processes owned by
+.IR jail .
+This may be either the
+.B jid
+or
+.B name
+of the jail.
+Use
+.B 0
+to limit to host processes.
+Using this option implies the
+.B \-j
+flag.
+.PP
.BI \-U username
Show only those processes owned by
.IR username .
@@ -315,6 +332,12 @@ Toggle the display of
.IR jail (8)
ID.
.TP
+.B J
+Display only processes owned by a specific jail (prompt for jail).
+If the jail specified is simply \*(lq+\*(rq, then processes belonging
+to all jails and the host will be displayed.
+This will also enable the display of JID.
+.TP
.B P
Toggle the display of per-CPU statistics.
.TP
diff --git a/contrib/top/top.c b/contrib/top/top.c
index c2eb35d..6348304 100644
--- a/contrib/top/top.c
+++ b/contrib/top/top.c
@@ -38,7 +38,9 @@ char *copyright =
#include <signal.h>
#include <setjmp.h>
#include <ctype.h>
+#include <sys/jail.h>
#include <sys/time.h>
+#include <jail.h>
/* includes specific to top */
#include "display.h" /* interface to display package */
@@ -198,9 +200,9 @@ char *argv[];
fd_set readfds;
#ifdef ORDER
- static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPo";
+ static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJo";
#else
- static char command_chars[] = "\f qh?en#sdkriIutHmSCajzP";
+ static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJ";
#endif
/* these defines enumerate the "strchr"s of the commands in command_chars */
#define CMD_redraw 0
@@ -228,8 +230,9 @@ char *argv[];
#define CMD_jidtog 21
#define CMD_kidletog 22
#define CMD_pcputog 23
+#define CMD_jail 24
#ifdef ORDER
-#define CMD_order 24
+#define CMD_order 25
#endif
/* set the buffer for stdout */
@@ -261,6 +264,7 @@ char *argv[];
ps.uid = -1;
ps.thread = No;
ps.wcpu = 1;
+ ps.jid = -1;
ps.jail = No;
ps.kidle = Yes;
ps.command = NULL;
@@ -288,7 +292,7 @@ char *argv[];
optind = 1;
}
- while ((i = getopt(ac, av, "CSIHPabijnquvzs:d:U:m:o:t")) != EOF)
+ while ((i = getopt(ac, av, "CSIHPabijJ:nquvzs:d:U:m:o:t")) != EOF)
{
switch(i)
{
@@ -413,6 +417,15 @@ char *argv[];
ps.jail = !ps.jail;
break;
+ case 'J': /* display only jail's processes */
+ if ((ps.jid = jail_getid(optarg)) == -1)
+ {
+ fprintf(stderr, "%s: unknown jail\n", optarg);
+ exit(1);
+ }
+ ps.jail = 1;
+ break;
+
case 'P':
pcpu_stats = !pcpu_stats;
break;
@@ -425,7 +438,7 @@ char *argv[];
fprintf(stderr,
"Top version %s\n"
"Usage: %s [-abCHIijnPqStuvz] [-d count] [-m io | cpu] [-o field] [-s time]\n"
-" [-U username] [number]\n",
+" [-J jail] [-U username] [number]\n",
version_string(), myname);
exit(1);
}
@@ -1085,6 +1098,44 @@ restart:
reset_display();
putchar('\r');
break;
+
+ case CMD_jail:
+ new_message(MT_standout,
+ "Jail to show: ");
+ if (readline(tempbuf2, sizeof(tempbuf2), No) > 0)
+ {
+ if (tempbuf2[0] == '+' &&
+ tempbuf2[1] == '\0')
+ {
+ ps.jid = -1;
+ }
+ else if ((i = jail_getid(tempbuf2)) == -1)
+ {
+ new_message(MT_standout,
+ " %s: unknown jail", tempbuf2);
+ no_command = Yes;
+ }
+ else
+ {
+ ps.jid = i;
+ }
+ if (ps.jail == 0) {
+ ps.jail = 1;
+ new_message(MT_standout |
+ MT_delayed, " Displaying jail "
+ "ID.");
+ header_text =
+ format_header(uname_field);
+ reset_display();
+ }
+ putchar('\r');
+ }
+ else
+ {
+ clear_message();
+ }
+ break;
+
case CMD_kidletog:
ps.kidle = !ps.kidle;
new_message(MT_standout | MT_delayed,
OpenPOWER on IntegriCloud