summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2007-01-03 18:57:49 +0000
committerotto <otto@openbsd.org>2007-01-03 18:57:49 +0000
commit49ac70bab815d179ec883cd7de3b160cdd7b19f0 (patch)
tree1b242726bbde6e9e78650e2bf555240bc10a5fbd
parentAfter the firmware has been loaded to the chip, read the exact firmware (diff)
downloadwireguard-openbsd-49ac70bab815d179ec883cd7de3b160cdd7b19f0.tar.xz
wireguard-openbsd-49ac70bab815d179ec883cd7de3b160cdd7b19f0.zip
Add a 'g' command to only show processes having a string in their
command name. ok deraadt@
-rw-r--r--usr.bin/top/machine.c9
-rw-r--r--usr.bin/top/top.113
-rw-r--r--usr.bin/top/top.c29
3 files changed, 43 insertions, 8 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index e9a11cee2f1..3b4d5242a61 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.55 2007/01/02 19:09:24 otto Exp $ */
+/* $OpenBSD: machine.c,v 1.56 2007/01/03 18:57:49 otto Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -341,7 +341,7 @@ caddr_t
get_process_info(struct system_info *si, struct process_select *sel,
int (*compare) (const void *, const void *))
{
- int show_idle, show_system, show_threads, show_uid, show_pid;
+ int show_idle, show_system, show_threads, show_uid, show_pid, show_cmd;
int total_procs, active_procs;
struct kinfo_proc2 **prefp, *pp;
@@ -365,6 +365,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
show_threads = sel->threads;
show_uid = sel->uid != (uid_t)-1;
show_pid = sel->pid != (pid_t)-1;
+ show_cmd = sel->command != NULL;
/* count up process states and get pointers to interesting procs */
total_procs = 0;
@@ -387,7 +388,9 @@ get_process_info(struct system_info *si, struct process_select *sel,
(show_idle || pp->p_pctcpu != 0 ||
pp->p_stat == SRUN) &&
(!show_uid || pp->p_ruid == sel->uid) &&
- (!show_pid || pp->p_pid == sel->pid)) {
+ (!show_pid || pp->p_pid == sel->pid) &&
+ (!show_cmd || strstr(pp->p_comm,
+ sel->command))) {
*prefp++ = pp;
active_procs++;
}
diff --git a/usr.bin/top/top.1 b/usr.bin/top/top.1
index e76b5ad0d6e..31470badb05 100644
--- a/usr.bin/top/top.1
+++ b/usr.bin/top/top.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: top.1,v 1.34 2006/12/27 07:24:52 otto Exp $
+.\" $OpenBSD: top.1,v 1.35 2007/01/03 18:57:49 otto Exp $
.\"
.\" Copyright (c) 1997, Jason Downs. All rights reserved.
.\"
@@ -33,6 +33,7 @@
.Nm top
.Op Fl bCIinqSTu
.Op Fl d Ar count
+.Op Fl g Ar command
.Op Fl o Ar field
.Op Fl p Ar pid
.Op Fl s Ar time
@@ -97,6 +98,10 @@ to be shown before
automatically exits.
For intelligent terminals, no upper limit is set.
The default is 1 for dumb terminals.
+.It Fl g Ar command
+Show only processes that contain the string
+.Ar command
+in their command name.
.It Fl I
Do not display idle processes.
By default,
@@ -273,6 +278,12 @@ Display a list of system errors (if any) generated by the last
or
.Li renice
command.
+.It g
+Display only processes that contain a string in their command name
+(prompt for string).
+If the string specified is simply
+.Dq + ,
+then no process name matching will be done.
.It I or i
Toggle the display of idle processes.
.It k
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index e072259799d..f70f6987a3d 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.44 2006/12/27 07:24:52 otto Exp $ */
+/* $OpenBSD: top.c,v 1.45 2007/01/03 18:57:49 otto Exp $ */
/*
* Top users/processes display for Unix
@@ -128,6 +128,7 @@ char topn_specified = No;
#define CMD_pid 17
#define CMD_command 18
#define CMD_threads 19
+#define CMD_grep 20
static void
usage(void)
@@ -135,7 +136,7 @@ usage(void)
extern char *__progname;
fprintf(stderr,
- "usage: %s [-bCIinqSTu] [-d count] [-o field] [-p pid] [-s time] [-U username] [number]\n",
+ "usage: %s [-bCIinqSTu] [-d count] [-g command] [-o field] [-p pid] [-s time]\n\t[-U username] [number]\n",
__progname);
}
@@ -145,7 +146,7 @@ parseargs(int ac, char **av)
char *endp;
int i;
- while ((i = getopt(ac, av, "STICbinqus:d:p:U:o:")) != -1) {
+ while ((i = getopt(ac, av, "STICbinqus:d:p:U:o:g:")) != -1) {
switch (i) {
case 'C':
show_args = Yes;
@@ -236,6 +237,10 @@ parseargs(int ac, char **av)
order_name = optarg;
break;
+ case 'g': /* grep command name */
+ ps.command = strdup(optarg);
+ break;
+
default:
usage();
exit(1);
@@ -522,7 +527,7 @@ rundisplay(void)
int change, i;
struct pollfd pfd[1];
uid_t uid;
- static char command_chars[] = "\f qh?en#sdkriIuSopCT";
+ static char command_chars[] = "\f qh?en#sdkriIuSopCTg";
/*
* assume valid command unless told
@@ -868,6 +873,22 @@ rundisplay(void)
ps.threads ? "D" : "Not d");
break;
+ case CMD_grep:
+ new_message(MT_standout,
+ "Grep command name: ");
+ if (readline(tempbuf2, sizeof(tempbuf2), No) > 0) {
+ free(ps.command);
+ if (tempbuf2[0] == '+' &&
+ tempbuf2[1] == '\0')
+ ps.command = NULL;
+ else
+ ps.command = strdup(tempbuf2);
+ if (putchar('\r') == EOF)
+ exit(1);
+ } else
+ clear_message();
+ break;
+
default:
new_message(MT_standout, " BAD CASE IN SWITCH!");
if (putchar('\r') == EOF)