2022-11-04 17:09:16 +08:00
|
|
|
From 6e59f5e746c15df4d4b53f2df85b64aa1f10d0c3 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: xuchunmei <xuchunmei@huawei.com>
|
|
|
|
|
Date: Fri, 11 Jan 2019 01:29:55 -0500
|
|
|
|
|
Subject: [PATCH] procps-ng: add -M and -N options for top
|
|
|
|
|
|
|
|
|
|
Signed-off-by: xuchunmei <xuchunmei@huawei.com>
|
|
|
|
|
Signed-off-by: zhoujie <zhoujie133@huawei.com>
|
2023-02-01 15:46:27 +08:00
|
|
|
Signed-off-by: Qiang Wei <qiang.wei@suse.com>
|
2023-11-01 10:15:03 +08:00
|
|
|
Signed-off-by: liweigang <weigangli99@gmail.com>
|
2022-11-04 17:09:16 +08:00
|
|
|
---
|
2023-11-01 10:15:03 +08:00
|
|
|
src/top/top.c | 15 ++++++++++++++-
|
|
|
|
|
src/top/top_nls.c | 2 ++
|
2022-11-04 17:09:16 +08:00
|
|
|
2 files changed, 16 insertions(+), 1 deletion(-)
|
|
|
|
|
|
2023-11-01 10:15:03 +08:00
|
|
|
diff --git a/src/top/top.c b/src/top/top.c
|
|
|
|
|
index 969c553..466341f 100644
|
2023-02-01 15:46:27 +08:00
|
|
|
--- a/src/top/top.c
|
|
|
|
|
+++ b/src/top/top.c
|
2023-11-01 10:15:03 +08:00
|
|
|
@@ -4243,7 +4243,7 @@ default_or_error:
|
2022-11-04 17:09:16 +08:00
|
|
|
* overridden -- we'll force some on and negate others in our
|
|
|
|
|
* best effort to honor the loser's (oops, user's) wishes... */
|
|
|
|
|
static void parse_args (int argc, char **argv) {
|
|
|
|
|
- static const char sopts[] = "bcd:E:e:Hhin:Oo:p:SsU:u:Vw::1";
|
|
|
|
|
+ static const char sopts[] = "bcd:E:e:Hhin:Oo:p:SsU:u:Vw::1MN:";
|
|
|
|
|
static const struct option lopts[] = {
|
|
|
|
|
{ "batch-mode", no_argument, NULL, 'b' },
|
|
|
|
|
{ "cmdline-toggle", no_argument, NULL, 'c' },
|
2023-11-01 10:15:03 +08:00
|
|
|
@@ -4264,6 +4264,8 @@ static void parse_args (int argc, char **argv) {
|
2022-11-04 17:09:16 +08:00
|
|
|
{ "version", no_argument, NULL, 'V' },
|
|
|
|
|
{ "width", optional_argument, NULL, 'w' },
|
|
|
|
|
{ "single-cpu-toggle", no_argument, NULL, '1' },
|
|
|
|
|
+ { "sort-by-mem", no_argument, NULL, 'M' },
|
|
|
|
|
+ { "display-task-num", required_argument, NULL, 'N' },
|
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
|
};
|
|
|
|
|
float tmp_delay = FLT_MAX;
|
2023-11-01 10:15:03 +08:00
|
|
|
@@ -4386,6 +4388,17 @@ static void parse_args (int argc, char **argv) {
|
2022-11-04 17:09:16 +08:00
|
|
|
error_exit(fmtmk(N_fmt(BAD_widtharg_fmt), cp));
|
|
|
|
|
Width_mode = (int)tmp;
|
|
|
|
|
continue;
|
|
|
|
|
+ case 'M':
|
|
|
|
|
+ {
|
|
|
|
|
+ Curwin->rc.sortindx = EU_MEM;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'N':
|
|
|
|
|
+ {
|
|
|
|
|
+ if (sscanf(cp, "%d", &Curwin->rc.maxtasks) != 1 || Curwin->rc.maxtasks < 0)
|
|
|
|
|
+ error_exit(fmtmk("bad iterations arg '%s'", cp));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
default:
|
2023-11-01 10:15:03 +08:00
|
|
|
/* we'll rely on getopt for any error message while
|
|
|
|
|
forcing an EXIT_FAILURE with an empty string ... */
|
|
|
|
|
diff --git a/src/top/top_nls.c b/src/top/top_nls.c
|
|
|
|
|
index d7ab8dc..0201d64 100644
|
2023-02-01 15:46:27 +08:00
|
|
|
--- a/src/top/top_nls.c
|
|
|
|
|
+++ b/src/top/top_nls.c
|
|
|
|
|
@@ -431,6 +431,8 @@ static void build_norm_nlstab (void) {
|
2022-11-04 17:09:16 +08:00
|
|
|
" -u, --filter-only-euser =USER show only processes owned by USER\n"
|
|
|
|
|
" -w, --width [=COLUMNS] change print width [,use COLUMNS]\n"
|
|
|
|
|
" -1, --single-cpu-toggle reverse last remembered '1' state\n"
|
|
|
|
|
+ " -M, --sort-by-mem show tasks by memory usage\n"
|
|
|
|
|
+ " -N, --show-task-num show the specified number of tasks\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" -h, --help display this help text, then exit\n"
|
|
|
|
|
" -V, --version output version information & exit\n"
|
2023-11-01 10:15:03 +08:00
|
|
|
--
|
|
|
|
|
2.41.0
|
|
|
|
|
|