Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Jul 1998 20:46:01 +0200 (CEST)
From:      finrod@niobe.ewox.org
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/7253: [PATCH] Make top(1) ignore itself
Message-ID:  <199807111846.UAA01915@niobe.ewox.org>

next in thread | raw e-mail | index | archive | help

>Number:         7253
>Category:       bin
>Synopsis:       [PATCH] Make top(1) ignore itself
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 11 11:50:00 PDT 1998
>Last-Modified:
>Originator:     Dag-Erling Coïdan Smørgrav
>Organization:
Ewox
>Release:        FreeBSD 3.0-CURRENT i386
>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++;

>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807111846.UAA01915>