From finrod@niobe.ewox.org  Sat Jul 11 11:46:20 1998
Received: from niobe.ewox.org (ppp068.uio.no [129.240.240.73])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA01085
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 11 Jul 1998 11:46:11 -0700 (PDT)
          (envelope-from finrod@niobe.ewox.org)
Received: (from finrod@localhost)
	by niobe.ewox.org (8.8.8/8.8.8) id UAA01915;
	Sat, 11 Jul 1998 20:46:01 +0200 (CEST)
	(envelope-from finrod)
Message-Id: <199807111846.UAA01915@niobe.ewox.org>
Date: Sat, 11 Jul 1998 20:46:01 +0200 (CEST)
From: finrod@niobe.ewox.org
Reply-To: finrod@niobe.ewox.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] Make top(1) ignore itself
X-Send-Pr-Version: 3.2

>Number:         7253
>Category:       bin
>Synopsis:       [PATCH] Make top(1) ignore itself
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 11 11:50:00 PDT 1998
>Closed-Date:    Wed Aug 12 03:50:23 PDT 1998
>Last-Modified:  Wed Aug 12 03:50:39 PDT 1998
>Originator:     Dag-Erling Codan Smrgrav
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Ewox
>Environment:

Nothing relevant.

>Description:

For obvious reasons, top(1) usually ranks quite high on the list of
processes it displays. However, it is usually totally uninteresting
and quite annoying since it keeps bouncing up and down the list.

This patch adds a command-line switch (-t) and an interactive command
(t) to top(1) which make it ignore itself when listing processes.

>How-To-Repeat:

finrod@niobe ~$ top -b  
last pid:  1852;  load averages:  0.02,  0.06,  0.07    20:42:39
65 processes:  1 running, 64 sleeping

Mem: 40M Active, 12M Inact, 21M Wired, 6264K Cache, 8233K Buf, 45M Free
Swap: 512M Total, 128K Used, 512M Free


  PID USERNAME PRI NICE  SIZE    RES STATE    TIME   WCPU    CPU COMMAND
 1852 finrod    31   0  1084K   808K RUN      0:00  1.56%  0.08% top
  583 finrod     2   0  5532K  4952K select   2:18  0.00%  0.00% emacs
[...]

>Fix:
	
Index: machine.h
===================================================================
RCS file: /home/ncvs/src/contrib/top/machine.h,v
retrieving revision 1.2
diff -u -r1.2 machine.h
--- machine.h	1997/03/23 18:52:54	1.2
+++ machine.h	1998/07/11 16:24:39
@@ -46,6 +46,7 @@
 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) */
Index: top.X
===================================================================
RCS file: /home/ncvs/src/contrib/top/top.X,v
retrieving revision 1.4
diff -u -r1.4 top.X
--- top.X	1998/01/13 14:17:10	1.4
+++ top.X	1998/07/11 18:36:07
@@ -9,7 +9,7 @@
 .SH SYNOPSIS
 .B top
 [
-.B \-SbiInqu
+.B \-SbiInqut
 ] [
 .BI \-d count
 ] [
@@ -81,6 +81,11 @@
 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 @@
 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 @@
 (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
Index: top.c
===================================================================
RCS file: /home/ncvs/src/contrib/top/top.c,v
retrieving revision 1.2
diff -u -r1.2 top.c
--- top.c	1997/03/23 18:52:55	1.2
+++ top.c	1998/07/11 16:32:52
@@ -185,9 +185,9 @@
     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 @@
 #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 @@
 
     /* initialize some selection options */
     ps.idle    = Yes;
+    ps.self    = -1;
     ps.system  = No;
     ps.uid     = -1;
     ps.command = NULL;
@@ -259,7 +261,7 @@
 	    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 @@
 #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);
 	    }
@@ -834,6 +840,14 @@
 				new_message(MT_standout | MT_delayed,
 				    " %sisplaying idle processes.",
 				    ps.idle ? "D" : "Not d");
+				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;
 
Index: machine.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.11
diff -u -r1.11 machine.c
--- machine.c	1998/06/21 18:00:34	1.11
+++ machine.c	1998/07/11 16:23:46
@@ -458,6 +458,7 @@
 
     /* 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 @@
 
     /* 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 @@
 	 *  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++;

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Tue Jul 21 23:18:35 PDT 1998 
State-Changed-Why:  
This sounds like a good task for Dag-Erling, doesn't it ?  :-) 


Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: phk 
Responsible-Changed-When: Tue Jul 21 23:18:35 PDT 1998 
Responsible-Changed-Why:  
. 

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smrgrav)
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/7253 
Date: Wed, 22 Jul 1998 11:05:17 +0200

 >Yeah. The reason why I send-pr'ed it is that
 >
 > a) I'm not sure it's actually worth committing
 
 I think it is.
 
 > b) I'm not sure wether to commit the patch in our tree, or submit it
 >    to the author of top, since I've made changes to the generic parts
 >    of top, not just the FreeBSD-specific parts.
 
 Ideally you should offer it to the maintainer of top, if they don't
 want it or have gone missing, commit it to current.
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "ttyv0" -- What UNIX calls a $20K state-of-the-art, 3D, hi-res color terminal
State-Changed-From-To: suspended->closed 
State-Changed-By: des 
State-Changed-When: Wed Aug 12 03:50:23 PDT 1998 
State-Changed-Why:  
MFCed. 
>Unformatted:
