aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-10-31 19:44:32 -0500
committerRob Landley <rob@landley.net>2017-10-31 19:44:32 -0500
commite949f63c0e3fad8dfff6fa28ea2e6206efe18e99 (patch)
tree59f3f3d33eb8be4c8d0ed926f79f7ab7a727e598 /toys
parente913247fec162437920266182834aedadcb03004 (diff)
downloadtoybox-e949f63c0e3fad8dfff6fa28ea2e6206efe18e99.tar.gz
Add top -m, fix width truncating for narrow screens (off by one), and add iotop -H
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/ps.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index aef2a7f7..8d643576 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -46,8 +46,10 @@
USE_PS(NEWTOY(ps, "k(sort)*P(ppid)*aAdeflMno*O*p(pid)*s*t*Tu*U*g*G*wZ[!ol][+Ae][!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
// stayroot because iotop needs root to read other process' proc/$$/io
-USE_TOP(NEWTOY(top, ">0m" "O*Hk*o*p*u*s#<1d#=3<1n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
-USE_IOTOP(NEWTOY(iotop, ">0AaKO" "k*o*p*u*s#<1=7d#=3<1n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))
+// TOP and IOTOP have a large common option block used for common processing,
+// the default values are different but the flags are in the same order.
+USE_TOP(NEWTOY(top, ">0O*" "Hk*o*p*u*s#<1d#=3<1m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d#=3<1m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))
USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PKILL(NEWTOY(pkill, "?Vu*U*t*s*P*g*G*fnovxl:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
@@ -130,7 +132,7 @@ config TOP
bool "top"
default y
help
- usage: top [-Hbq] [-k FIELD,] [-o FIELD,] [-s SORT] [-n NUMBER] [-d SECONDS] [-p PID,] [-u USER,]
+ usage: top [-Hbq] [-k FIELD,] [-o FIELD,] [-s SORT] [-n NUMBER] [-m LINES] [-d SECONDS] [-p PID,] [-u USER,]
Show process activity in real time.
@@ -141,6 +143,7 @@ config TOP
-s Sort by field number (1-X, default 9)
-b Batch mode (no tty)
-d Delay SECONDS between each cycle (default 3)
+ -m Maximum number of tasks to show
-n Exit after NUMBER iterations
-p Show these PIDs
-u Show these USERs
@@ -160,8 +163,10 @@ config IOTOP
-A All I/O, not just disk
-a Accumulated I/O (not percentage)
+ -H Show threads
-K Kilobytes
-k Fallback sort FIELDS (default -[D]IO,-ETIME,-PID)
+ -m Maximum number of tasks to show
-O Only show processes doing I/O
-o Show FIELDS (default PID,PR,USER,[D]READ,[D]WRITE,SWAP,[D]IO,COMM)
-s Sort by field number (0-X, default 6)
@@ -243,6 +248,7 @@ GLOBALS(
} ps;
struct {
long n;
+ long m;
long d;
long s;
struct arg_list *u;
@@ -561,6 +567,7 @@ static void show_ps(void *p)
// Output the field, appropriately padded
// Minimum one space between each field
+ if (width<2) break;
if (field != TT.fields) {
putchar(' ');
width--;
@@ -1435,6 +1442,7 @@ static void top_common(
terminal_probesize(&TT.width, &TT.height);
}
}
+ if (TT.top.m) TT.height = TT.top.m+5;
lines = TT.height;
}
if (recalc && !(toys.optflags&FLAG_q)) {