aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ps.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2017-01-27 12:54:25 -0800
committerRob Landley <rob@landley.net>2017-01-28 16:35:50 -0600
commit8b2646e1c048163e01a8dd7349f1e23d21ad76b0 (patch)
tree032791eae325e97957a046ca8f71699f1da65606 /toys/posix/ps.c
parent113971d21a51f40aecad759da54acbd694a9dd90 (diff)
downloadtoybox-8b2646e1c048163e01a8dd7349f1e23d21ad76b0.tar.gz
top -H is more useful if it shows thread names.
I knew that just showing the process name was a divergence from traditional Android behavior, but I was curious to see whether anyone cared. Bug reports show that they do. I've not made this conditional on CFG_TOYBOX_ON_ANDROID on the assumption that this is more useful for everyone else too. (Why are you asking for per-thread information if you don't actually want to be able to identify individual threads?) Why not _just_ show the thread name? Because on Android at least, every process has lots of identically-named threads; everyone has GC threads, everyone has JIT threads, and so knowing _just_ the thread name is rarely useful. Why show thread name first? Because the kernel limits thread names to 15 bytes plus a NUL, so any left-over space should go to the process name, so that should come last. Why call the thread name THREAD? Because "CMD" isn't obviously "thread name" to folks who don't know how this is implemented behind the scenes. This change also removes an incorrect "usage:" comment. None of the other commands in this file duplicated their "usage:" lines, and this copy wasn't even close to being correct. Bug: http://b/34610082
Diffstat (limited to 'toys/posix/ps.c')
-rw-r--r--toys/posix/ps.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 8404e793..35763509 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1598,10 +1598,9 @@ static void top_setup(char *defo, char *defk)
void top_main(void)
{
- // usage: [-h HEADER] -o OUTPUT -k SORT
-
- sprintf(toybuf, "PID,USER,%s%%CPU,%%MEM,TIME+,ARGS",
- TT.top.O ? "" : "PR,NI,VIRT,RES,SHR,S,");
+ sprintf(toybuf, "PID,USER,%s%%CPU,%%MEM,TIME+,%s",
+ TT.top.O ? "" : "PR,NI,VIRT,RES,SHR,S,",
+ toys.optflags&FLAG_H ? "CMD:15=THREAD,NAME=PROCESS" : "ARGS");
if (!TT.top.s) TT.top.s = TT.top.O ? 3 : 9;
top_setup(toybuf, "-%CPU,-ETIME,-PID");
if (TT.top.O) {