aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ps.c
AgeCommit message (Collapse)Author
2017-08-31Another try at fixing the ps segfault resulting from /proc entries vanishingRob Landley
out from under us due to asyncronous process exit. The directory we're traversing vanishing can result in DIRTREE_ABORTVAL being returned, which we turn into a NUL entry, but then we were trying to look at that null entry's children. Oops.
2017-06-19Manually inline TOP_COMMON and PGKILL_COMMON help text until I can teachRob Landley
the help infrastructure to handle it. (The lifetime rules are all wrong for hunks that get reused. Needs a largeish rewrite.)
2017-03-28ps: don't query for terminal size if not a tty.Josh Gao
`ps -A | cat` shouldn't have different output depending on the size of your terminal window.
2017-03-21dirtree_flagread() returns DIRTREE_ABORTVAL when the initial node doesn'tRob Landley
exist, which can hit ps when /proc isn't there or /proc/$PID/task isn't there (because process exited between the time we checked its contents and the time we looked for its threads).
2017-02-20If the last ps field is left justified, it extends to the width of the screen.Rob Landley
(Recent "show + for last char when truncated" change broke that, putting it back.)
2017-02-06ps -l has 4 chars left for "cmd", switch "ADDR" to "BIT" to save space.Rob Landley
2017-02-06Make tty size failure to enable -w (Elliott prefers that), and fix last fieldRob Landley
to be left justified again.
2017-02-05Don't set SIGWINCH when reading ANSI size probe data, it causes a loop.Rob Landley
2017-02-05Bugfix: last field was padding to width with trailing spaces (oops), andRob Landley
when we can't query terminal size pad to 80 but add -w.
2017-02-05Default to width 80 when tty size probe fails (ala serial console).Rob Landley
(It was defaulting to 99999 but not FLAG_w, so it tried to _pad_ to 99999.)
2017-02-03Fix typo in pgrep help.Elliott Hughes
2017-02-01Extend default USER length to 12 and output "+" as last character of truncatedRob Landley
(left-justified) fields.
2017-01-31ps bugfix: len of TTY field doesn't include null terminator, so memmove shouldRob Landley
subtract one _less_ than /dev prefix length or string isn't terminated.
2017-01-28Tweak -w help text to clarify that it prevents truncating _any_ fields, notRob Landley
just for terminal width.
2017-01-28Add missing `static`s and remove an unused function.Elliott Hughes
2017-01-28top -H is more useful if it shows thread names.Elliott Hughes
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
2016-12-09Pass DIRTREE_PROC through the ps callbacks.Elliott Hughes
2016-12-08Add DIRTREE_PROC to skip non-numeric entries and make ps/top etc use it.Rob Landley
2016-11-02Fix control flow integrity check failure in ps.Evgenii Stepanov
This fixes an indirect function call through a pointer of an incompatible type. See http://clang.llvm.org/docs/ControlFlowIntegrity.html for more details.
2016-10-12Stop renaming the ADDR field to PC on Android.Elliott Hughes
It's causing confusion, and it's not obvious that anyone's relying on it (and even if they are, let's try to find and fix them first).
2016-10-08Teach ps -w not to truncate any fields.Rob Landley
2016-10-08Evgenii Stepanov found a bug where argv0len was set wrong for threadsRob Landley
(no /proc/$PID/cmdline so setting was skipped and previous value retained), which led to memcpy() with an overlapping source/dest range (annoying asan). Fix: move temp variable and assignment outside the if() statement so we assign zero if we can''t read the file.
2016-09-29Accept extra ps arguments as additional pids.Elliott Hughes
POSIX says nothing, but traditional ps lets you say "ps 123" in addition to "ps -p 123". (You can mix and match too: "ps -p 123,124 666 667" works fine.) Bug: 31778761
2016-09-28Show thread names with "ps -T" on Android.Elliott Hughes
Android uses NAME rather than CMD by default, but that's not what we want with -T. Noticed because it broke systrace's reporting of thread names (see https://developer.android.com/studio/profile/systrace.html). Bug: 31741954
2016-07-13Increase ps' default RSS and VSIZE widths.Elliott Hughes
This is enough for everything on Android and everything except Java on my desktop. Even desktop Chrome fits!
2016-06-28Fix a "may be used uninitialized".Rob Landley
2016-06-17Make it clearer that CMD is the thread name.Elliott Hughes
It should come as no surprise to those who followed the development of this that it's not well known which of the various names is actually the thread name. Adding "thread" to the ps --help output seems like a good idea. I'm also assuming that "stat2" was meant to read "stat[2]", since that's how it mostly appeared on the list while discussing this. Still fits in 80 columns.
2016-06-15Add readlink0() and readlinkat0() which null terminate the data.Rob Landley
2016-06-10Shuffle arguments around (TNAME->NAME->COMM->CMD), working around posixRob Landley
constraints while still trying to get sane behavior. Discard the old CMD, move COMM to CMD, move the old NAME to COMM, and move TNAME to NAME. Posix assumes argv[] is the only source of process name data, but Linux has three sources (/proc/$PID/cmdline, /proc/$PID/exe, /proc/$PID/stat field 2) and android uses multiple sources simultaneously to identify its processes and threads. Toybox ps also assumes that the field names displayed in the headers can be fed to -o to get that output, which is an assumption posix's ps spec clearly does not have. Before we were erring on the side of posix, now we're erring on the side of sanity. CMD now shows stat[2], all the time. The posix -f behavior change is now just an ARGS=CMD alias in the -f default command line, which -o overrides. (Before -f changed the behavior of -o CMD, which is closer to what posix says but is _insane_ and we've stopped doing it.) COMM now shows /proc/$PID/exe minus the path. (I'm aware posix says argv[0] here, but it says argv everywhere.) NAME is now argv[0] of $PID. TNAME went away. Both $COMM and $NAME show the data for $PID, which is a thread's parent process when $TID != $PID.
2016-06-10Revert commit e02e41373ea3, we're always initializing the TNAME stringRob Landley
field (that's the ptb/tb switching in get_ps) so it's never blank, so this doesn't trigger. (Conditionally initializing it would save runtime memory, but at the expense of more complex code.)
2016-06-10HACK: restore Android ps behavior.Elliott Hughes
"NAME" is no longer doing what we want; "TNAME" is what "NAME" used to be, except that "TNAME" implies -T. This patch switches us over to "TNAME", disables the implicit -T. Change-Id: I5553703d3939b24eaf39976162d2f75a591e1ce8
2016-06-08Fix ps bug, last field wasn't expanding to width.Rob Landley
(Still fixing the fallout from that "Don't truncate number fields" logic rewrite.)
2016-06-08Change the TNAME behavior to "Show parent argv[0]. If that's blank, showour ↵Rob Landley
argv[0]. If that's blank, show [stat2]." That way threads show their parents, parents show themselves, and kernel threads show the [stat2] name.
2016-06-04Basic success/failure return from pgrep/pkill.Elliott Hughes
The man page says they also return 2 for syntax errors and 3 for "fatal error: out of memory etc", but I don't know how to implement that and don't need it (or have any reason to believe anyone needs it). Bug: 29092208
2016-06-04ps: Show [stat2] for any otherwise blank process name field, expand TNAME to 27,Rob Landley
use generated constant for stat field parsing loop.
2016-05-27Add -o TNAME for android, fix display of last field (retain left justifificationRob Landley
when trimmed for screen width), make ARGS path trimming logic work with spaces in path.
2016-05-24The "show parent command path" commit changed the criteria for active nodes,Rob Landley
and the collate logic wasn't updated. (Oops.)
2016-05-23Fix remaining pkill tests.Elliott Hughes
I don't know that anyone cares, but these failures made me think I'd broken something while testing the -SIGNAL patch. The -s parsing wasn't taking into account that -s 0 is a special case, and the -o test was assuming that pkill can tell the difference between two processes started at roughly the same time. Hopefully there's higher-resolution data available that can avoid the need for yet another sleep in the tests.
2016-05-23Fix pkill -9.Elliott Hughes
This fixes the existing test. Internal Android bug 28877702. I've left -l as-is, even though the desktop doesn't support that.
2016-05-22Don't truncate number fields for anything but right edge of screen, insteadRob Landley
let them overflow and try to reclaim extra space from later short fields.
2016-05-22Make -o COMMAND show parent command path for threads, and use saved lengthRob Landley
calculations instead of doing strlen() on strings again to store lengths.
2016-05-22Comment and help text tweaks.Rob Landley
2016-05-20Add bufgetgrgid()Rob Landley
2016-05-17Add bufgetpwuid. (Repeated calls to getpwuid() are really expensive.)Rob Landley
2016-05-16Add top -ORob Landley
2016-05-05Add top -H.Elliott Hughes
Also enable the same behavior we have with ps, where adding a thread-related field implies that you're interested in threads. Also clean up the help text slightly --- we're still not including the TOP_COMMON help, but at least when we do, we'll have each option covered with no duplicates.
2016-05-05"top -b -n1" should end with a newline.Elliott Hughes
The use of TT.time to determine whether to use \r or \n is a little odd, but let's stick with that for now. Correct the spelling of millitime and add a test.
2016-05-04Elliott says -T should fetch threads even when not displaying thread fields.Rob Landley
2016-05-04Simplify ps android scheduling policy fetch slightly.Rob Landley
2016-04-30Add a ps "PCY" field for Android scheduling policy.Elliott Hughes