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
This commit is contained in:
parent
02e17f0b93
commit
1b60f97272
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=265249
@ -66,6 +66,7 @@ struct process_select
|
|||||||
int thread; /* show threads */
|
int thread; /* show threads */
|
||||||
int uid; /* only this uid (unless uid == -1) */
|
int uid; /* only this uid (unless uid == -1) */
|
||||||
int wcpu; /* show weighted cpu */
|
int wcpu; /* show weighted cpu */
|
||||||
|
int jid; /* only this jid (unless jid == -1) */
|
||||||
int jail; /* show jail ID */
|
int jail; /* show jail ID */
|
||||||
int kidle; /* show per-CPU idle threads */
|
int kidle; /* show per-CPU idle threads */
|
||||||
char *command; /* only this command (unless == NULL) */
|
char *command; /* only this command (unless == NULL) */
|
||||||
|
@ -20,6 +20,8 @@ top \- display and update information about the top cpu processes
|
|||||||
] [
|
] [
|
||||||
.BI \-s time
|
.BI \-s time
|
||||||
] [
|
] [
|
||||||
|
.BI \-J jail
|
||||||
|
] [
|
||||||
.BI \-U username
|
.BI \-U username
|
||||||
] [
|
] [
|
||||||
.I number
|
.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
|
but may vary on different operating systems. Note that
|
||||||
not all operating systems support this option.
|
not all operating systems support this option.
|
||||||
.TP
|
.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
|
.BI \-U username
|
||||||
Show only those processes owned by
|
Show only those processes owned by
|
||||||
.IR username .
|
.IR username .
|
||||||
@ -315,6 +332,12 @@ Toggle the display of
|
|||||||
.IR jail (8)
|
.IR jail (8)
|
||||||
ID.
|
ID.
|
||||||
.TP
|
.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
|
.B P
|
||||||
Toggle the display of per-CPU statistics.
|
Toggle the display of per-CPU statistics.
|
||||||
.TP
|
.TP
|
||||||
|
@ -38,7 +38,9 @@ char *copyright =
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <sys/jail.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <jail.h>
|
||||||
|
|
||||||
/* includes specific to top */
|
/* includes specific to top */
|
||||||
#include "display.h" /* interface to display package */
|
#include "display.h" /* interface to display package */
|
||||||
@ -198,9 +200,9 @@ char *argv[];
|
|||||||
fd_set readfds;
|
fd_set readfds;
|
||||||
|
|
||||||
#ifdef ORDER
|
#ifdef ORDER
|
||||||
static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPo";
|
static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJo";
|
||||||
#else
|
#else
|
||||||
static char command_chars[] = "\f qh?en#sdkriIutHmSCajzP";
|
static char command_chars[] = "\f qh?en#sdkriIutHmSCajzPJ";
|
||||||
#endif
|
#endif
|
||||||
/* these defines enumerate the "strchr"s of the commands in command_chars */
|
/* these defines enumerate the "strchr"s of the commands in command_chars */
|
||||||
#define CMD_redraw 0
|
#define CMD_redraw 0
|
||||||
@ -228,8 +230,9 @@ char *argv[];
|
|||||||
#define CMD_jidtog 21
|
#define CMD_jidtog 21
|
||||||
#define CMD_kidletog 22
|
#define CMD_kidletog 22
|
||||||
#define CMD_pcputog 23
|
#define CMD_pcputog 23
|
||||||
|
#define CMD_jail 24
|
||||||
#ifdef ORDER
|
#ifdef ORDER
|
||||||
#define CMD_order 24
|
#define CMD_order 25
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* set the buffer for stdout */
|
/* set the buffer for stdout */
|
||||||
@ -261,6 +264,7 @@ char *argv[];
|
|||||||
ps.uid = -1;
|
ps.uid = -1;
|
||||||
ps.thread = No;
|
ps.thread = No;
|
||||||
ps.wcpu = 1;
|
ps.wcpu = 1;
|
||||||
|
ps.jid = -1;
|
||||||
ps.jail = No;
|
ps.jail = No;
|
||||||
ps.kidle = Yes;
|
ps.kidle = Yes;
|
||||||
ps.command = NULL;
|
ps.command = NULL;
|
||||||
@ -288,7 +292,7 @@ char *argv[];
|
|||||||
optind = 1;
|
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)
|
switch(i)
|
||||||
{
|
{
|
||||||
@ -413,6 +417,15 @@ char *argv[];
|
|||||||
ps.jail = !ps.jail;
|
ps.jail = !ps.jail;
|
||||||
break;
|
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':
|
case 'P':
|
||||||
pcpu_stats = !pcpu_stats;
|
pcpu_stats = !pcpu_stats;
|
||||||
break;
|
break;
|
||||||
@ -425,7 +438,7 @@ char *argv[];
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Top version %s\n"
|
"Top version %s\n"
|
||||||
"Usage: %s [-abCHIijnPqStuvz] [-d count] [-m io | cpu] [-o field] [-s time]\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);
|
version_string(), myname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -1085,6 +1098,44 @@ char *argv[];
|
|||||||
reset_display();
|
reset_display();
|
||||||
putchar('\r');
|
putchar('\r');
|
||||||
break;
|
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:
|
case CMD_kidletog:
|
||||||
ps.kidle = !ps.kidle;
|
ps.kidle = !ps.kidle;
|
||||||
new_message(MT_standout | MT_delayed,
|
new_message(MT_standout | MT_delayed,
|
||||||
|
@ -21,8 +21,8 @@ WARNS?= 0
|
|||||||
CFLAGS+= -D"Table_size=${TOP_TABLE_SIZE}"
|
CFLAGS+= -D"Table_size=${TOP_TABLE_SIZE}"
|
||||||
.endif
|
.endif
|
||||||
|
|
||||||
DPADD= ${LIBTERMCAP} ${LIBM} ${LIBKVM}
|
DPADD= ${LIBTERMCAP} ${LIBM} ${LIBKVM} ${LIBJAIL}
|
||||||
LDADD= -ltermcap -lm -lkvm
|
LDADD= -ltermcap -lm -lkvm -ljail
|
||||||
|
|
||||||
CLEANFILES= sigdesc.h
|
CLEANFILES= sigdesc.h
|
||||||
SIGCONV_AWK= ${.CURDIR}/../../contrib/top/sigconv.awk
|
SIGCONV_AWK= ${.CURDIR}/../../contrib/top/sigconv.awk
|
||||||
|
@ -668,6 +668,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
|
|||||||
|
|
||||||
/* these are copied out of sel for speed */
|
/* these are copied out of sel for speed */
|
||||||
int show_idle;
|
int show_idle;
|
||||||
|
int show_jid;
|
||||||
int show_self;
|
int show_self;
|
||||||
int show_system;
|
int show_system;
|
||||||
int show_uid;
|
int show_uid;
|
||||||
@ -710,6 +711,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
|
|||||||
|
|
||||||
/* set up flags which define what we are going to select */
|
/* set up flags which define what we are going to select */
|
||||||
show_idle = sel->idle;
|
show_idle = sel->idle;
|
||||||
|
show_jid = sel->jid != -1;
|
||||||
show_self = sel->self == -1;
|
show_self = sel->self == -1;
|
||||||
show_system = sel->system;
|
show_system = sel->system;
|
||||||
show_uid = sel->uid != -1;
|
show_uid = sel->uid != -1;
|
||||||
@ -764,6 +766,10 @@ get_process_info(struct system_info *si, struct process_select *sel,
|
|||||||
/* skip processes that aren't doing I/O */
|
/* skip processes that aren't doing I/O */
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (show_jid && pp->ki_jid != sel->jid)
|
||||||
|
/* skip proc. that don't belong to the selected JID */
|
||||||
|
continue;
|
||||||
|
|
||||||
if (show_uid && pp->ki_ruid != (uid_t)sel->uid)
|
if (show_uid && pp->ki_ruid != (uid_t)sel->uid)
|
||||||
/* skip proc. that don't belong to the selected UID */
|
/* skip proc. that don't belong to the selected UID */
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user