Hi,
Sometimes it's handy to hide a user from top(1) output, on a desktop
system for example you might want to quickly hide yourself and see what
else is running.
The syntax for interactive mode is u -user, passwd(5) entries shouldn't
begin with that character.
'-', like '+', will clear all filters when used without an argument.
Non-interactive mode is unchanged.
Anyone like this?
-Bryan.
Index: display.c
===================================================================
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.42
diff -u -p -u -r1.42 display.c
--- display.c 15 Apr 2012 19:52:16 -0000 1.42
+++ display.c 1 Jun 2012 19:29:08 -0000
@@ -782,7 +782,7 @@ show_help(void)
"r count pid - renice process `pid' to nice value `count'\n"
"S - toggle the display of system processes\n"
"s time - change delay between displays to `time' seconds\n"
- "u user - display processes for `user' (u+ selects all
users)\n"
+ "u [-]user - show processes for `user' (u+ shows all, u -user
hides one)\n"
"\n");
if (smart_terminal) {
Index: machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.72
diff -u -p -u -r1.72 machine.c
--- machine.c 21 Apr 2012 03:14:50 -0000 1.72
+++ machine.c 1 Jun 2012 19:29:08 -0000
@@ -330,6 +330,7 @@ get_process_info(struct system_info *si,
int (*compare) (const void *, const void *))
{
int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd;
+ int hide_uid;
int total_procs, active_procs;
struct kinfo_proc **prefp, *pp;
int what = KERN_PROC_KTHREAD;
@@ -356,6 +357,7 @@ get_process_info(struct system_info *si,
show_system = sel->system;
show_threads = sel->threads;
show_uid = sel->uid != (uid_t)-1;
+ hide_uid = sel->huid != (uid_t)-1;
show_pid = sel->pid != (pid_t)-1;
show_cmd = sel->command != NULL;
@@ -381,6 +383,7 @@ get_process_info(struct system_info *si,
if (pp->p_stat != SZOMB &&
(show_idle || pp->p_pctcpu != 0 ||
pp->p_stat == SRUN) &&
+ (!hide_uid || pp->p_ruid != sel->huid) &&
(!show_uid || pp->p_ruid == sel->uid) &&
(!show_pid || pp->p_pid == sel->pid) &&
(!show_cmd || strstr(pp->p_comm,
Index: machine.h
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.16
diff -u -p -u -r1.16 machine.h
--- machine.h 10 Apr 2011 03:20:59 -0000 1.16
+++ machine.h 1 Jun 2012 19:29:08 -0000
@@ -74,6 +74,7 @@ struct process_select {
int system; /* show system processes */
int threads; /* show threads */
uid_t uid; /* only this uid (unless uid == -1) */
+ uid_t huid; /* hide this uid (unless huid == -1) */
pid_t pid; /* only this pid (unless pid == -1) */
char *command;/* only this command (unless == NULL) */
};
Index: top.1
===================================================================
RCS file: /cvs/src/usr.bin/top/top.1,v
retrieving revision 1.59
diff -u -p -u -r1.59 top.1
--- top.1 16 Dec 2011 14:50:24 -0000 1.59
+++ top.1 1 Jun 2012 19:29:08 -0000
@@ -354,11 +354,16 @@ Toggle the display of system processes.
Set the delay between screen updates to
.Ar time
seconds.
-.It u Ar user
+.It Xo
+.Ic u
+.Oo - Oc Ns Ar user
+.Xc
Show only those processes owned by
.Ar user .
.Sq u+
shows processes belonging to all users.
+.Sq u -user
+hides processes belonging to a single user.
.El
.Sh THE DISPLAY
.\" The actual display varies depending on the specific variant of Unix
Index: top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.77
diff -u -p -u -r1.77 top.c
--- top.c 20 Apr 2012 16:36:11 -0000 1.77
+++ top.c 1 Jun 2012 19:29:08 -0000
@@ -282,6 +282,7 @@ main(int argc, char *argv[])
ps.idle = Yes;
ps.system = No;
ps.uid = (uid_t)-1;
+ ps.huid = (uid_t)-1;
ps.pid = (pid_t)-1;
ps.command = NULL;
@@ -540,7 +541,6 @@ rundisplay(void)
char ch, *iptr;
int change, i;
struct pollfd pfd[1];
- uid_t uid;
static char command_chars[] = "\f qh?en#sdkriIuSopCHg+P1";
/*
@@ -774,15 +774,21 @@ rundisplay(void)
new_message(MT_standout,
"Username to show: ");
if (readline(tempbuf, sizeof(tempbuf)) > 0) {
- if (tempbuf[0] == '+' &&
+ if ((tempbuf[0] == '+' || tempbuf[0] == '-') &&
tempbuf[1] == '\0') {
ps.uid = (uid_t)-1;
- } else if ((uid = userid(tempbuf)) ==
(uid_t)-1) {
+ ps.huid = (uid_t)-1;
+ } else if (tempbuf[0] == '-') {
+ if ((ps.huid = userid(tempbuf+1)) ==
(uid_t)-1) {
+ new_message(MT_standout,
+ " %s: unknown user",
tempbuf);
+ no_command = Yes;
+ }
+ } else if ((ps.uid = userid(tempbuf)) ==
(uid_t)-1) {
new_message(MT_standout,
" %s: unknown user", tempbuf);
no_command = Yes;
- } else
- ps.uid = uid;
+ }
putr();
} else
clear_message();
@@ -899,6 +905,7 @@ rundisplay(void)
case CMD_add:
ps.uid = (uid_t)-1; /* uid */
+ ps.huid = (uid_t)-1;
ps.pid = (pid_t)-1; /* pid */
ps.system = old_system;
ps.command = NULL; /* grep */