Add -t option ('t' in interactive mode) to make top(1) ignore itself.

Attempts to contact the author of top(1) (William LeFebvre) have so
far been unsuccessful.

PR:		7253
Submitted by:	Yours Truly
This commit is contained in:
Dag-Erling Smørgrav 1998-08-04 14:10:48 +00:00
parent 05b73c60a4
commit e7cdb97253
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=38090
4 changed files with 36 additions and 8 deletions

View File

@ -46,6 +46,7 @@ struct system_info
struct process_select
{
int idle; /* show idle processes */
int self; /* show self */
int system; /* show system processes */
int uid; /* only this uid (unless uid == -1) */
char *command; /* only this command (unless == NULL) */

View File

@ -9,7 +9,7 @@ top \- display and update information about the top cpu processes
.SH SYNOPSIS
.B top
[
.B \-SbiInqu
.B \-SbiInqut
] [
.BI \-d count
] [
@ -81,6 +81,11 @@ intelligent terminal.
Do not display idle processes.
By default, top displays both active and idle processes.
.TP
.B \-t
Do not display the
.I top
process.
.TP
.B \-n
Use \*(lqnon-interactive\*(rq mode. This is identical to \*(lqbatch\*(rq
mode.
@ -153,8 +158,9 @@ can also be specified in the environment variable
The options
.BR \-I ,
.BR \-S ,
.BR \-u ,
and
.B \-u
.B \-t
are actually toggles. A second specification of any of these options
will negate the first. Thus a user who has the environment variable
.B TOP
@ -234,6 +240,10 @@ command.
(or
.BR I)
Toggle the display of idle processes.
.B t
Toggle the display of the
.I top
process.
.SH "THE DISPLAY"
The actual display varies depending on the specific variant of Unix
that the machine is running. This description may not exactly match

View File

@ -185,9 +185,9 @@ char *argv[];
fd_set readfds;
#ifdef ORDER
static char command_chars[] = "\f qh?en#sdkriIuo";
static char command_chars[] = "\f qh?en#sdkriIuto";
#else
static char command_chars[] = "\f qh?en#sdkriIu";
static char command_chars[] = "\f qh?en#sdkriIut";
#endif
/* these defines enumerate the "strchr"s of the commands in command_chars */
#define CMD_redraw 0
@ -206,8 +206,9 @@ char *argv[];
#define CMD_idletog 12
#define CMD_idletog2 13
#define CMD_user 14
#define CMD_selftog 15
#ifdef ORDER
#define CMD_order 15
#define CMD_order 16
#endif
/* set the buffer for stdout */
@ -232,6 +233,7 @@ char *argv[];
/* initialize some selection options */
ps.idle = Yes;
ps.self = -1;
ps.system = No;
ps.uid = -1;
ps.command = NULL;
@ -259,7 +261,7 @@ char *argv[];
optind = 1;
}
while ((i = getopt(ac, av, "SIbinqus:d:U:o:")) != EOF)
while ((i = getopt(ac, av, "SIbinqus:d:U:o:t")) != EOF)
{
switch(i)
{
@ -344,10 +346,14 @@ char *argv[];
#endif
break;
case 't':
ps.self = (ps.self == -1) ? getpid() : -1;
break;
default:
fprintf(stderr, "\
Top version %s\n\
Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
version_string(), myname);
exit(1);
}
@ -837,6 +843,14 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
putchar('\r');
break;
case CMD_selftog:
ps.self = (ps.self == -1) ? getpid() : -1;
new_message(MT_standout | MT_delayed,
" %sisplaying self.",
(ps.self == -1) ? "D" : "Not d");
putchar('\r');
break;
case CMD_user:
new_message(MT_standout,
"Username to show: ");

View File

@ -17,7 +17,7 @@
* Steven Wallace <swallace@freebsd.org>
* Wolfram Schneider <wosch@FreeBSD.org>
*
* $Id: machine.c,v 1.11 1998/06/21 18:00:34 dt Exp $
* $Id: machine.c,v 1.12 1998/07/27 12:21:58 wosch Exp $
*/
@ -458,6 +458,7 @@ int (*compare)();
/* these are copied out of sel for speed */
int show_idle;
int show_self;
int show_system;
int show_uid;
int show_command;
@ -476,6 +477,7 @@ int (*compare)();
/* set up flags which define what we are going to select */
show_idle = sel->idle;
show_self = sel->self;
show_system = sel->system;
show_uid = sel->uid != -1;
show_command = sel->command != NULL;
@ -494,6 +496,7 @@ int (*compare)();
* processes---these get ignored unless show_sysprocs is set.
*/
if (PP(pp, p_stat) != 0 &&
(show_self != PP(pp, p_pid)) &&
(show_system || ((PP(pp, p_flag) & P_SYSTEM) == 0)))
{
total_procs++;