diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-01-03 18:57:50 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2007-01-03 18:57:50 +0000 |
commit | 8d82cd3edd3a6c02bdb2d6fa079c205327b2d0c1 (patch) | |
tree | 76527fe8a4afdf7fbfb16681b9bd3b5586f9d6b0 /usr.bin/top/top.c | |
parent | 2b755dd4a0393ce908f591a2271beccbf31a3310 (diff) |
Add a 'g' command to only show processes having a string in their
command name. ok deraadt@
Diffstat (limited to 'usr.bin/top/top.c')
-rw-r--r-- | usr.bin/top/top.c | 29 |
1 files changed, 25 insertions, 4 deletions
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) |