freebsd-src/bin/ps
Piotr Pawel Stefaniak ca8c0d5e81 ps: extend the non-standard option -d (tree view) to work with -p
Initially it seemed that there were multiple possible ways to do it.

Processing option -p could conditionally add selected processes and
their descendants to the list for further work, but it is not guaranteed
to know whether the -d option has been used or not, and it also doesn't
have access to the process list just yet.

There is also descendant_sort() which has access to all possibly needed
information, but serves the purely post-processing purpose of sorting
output.

Then there is the loop that uses invocation information and full process
list to create a list of processes for final display. It seems the most
natural place to implement this, but indeterminate state of the process
list and volatility of the final list that is being created obstruct
adding an elegant search for all elements of process descendancy trees.

So I opted for adding another loop, just before the one I mentioned
above. For all selected processes it conditionally adds direct
descendants to the end of this list of selected processes.

Possible usage:
* ps -auxd -p $$
* ps -auxd -p 1
* while x=$(pgrep svnlite); do clear; ps auxd -p $x; sleep 2; done
* ps -auxd -p `pgrep make`

Reviewed by:	kevans, kaktus (earlier version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D24380
2020-05-07 16:56:18 +00:00
..
extern.h Add a "jail" keyword to list the name of a jail rather than its ID. 2018-03-13 18:30:26 +00:00
fmt.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
keyword.c Add a "jail" keyword to list the name of a jail rather than its ID. 2018-03-13 18:30:26 +00:00
Makefile Explicitly add unmarked bin/ binaries to the runtime package. 2016-02-09 16:58:50 +00:00
Makefile.depend DIRDEPS_BUILD: Update dependencies. 2017-10-31 00:07:04 +00:00
nlist.c General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00
print.c ps(1): fix some nits 2018-06-13 00:45:35 +00:00
ps.1 ps(1): Pet mandoc and igor 2018-10-31 17:47:08 +00:00
ps.c ps: extend the non-standard option -d (tree view) to work with -p 2020-05-07 16:56:18 +00:00
ps.h General further adoption of SPDX licensing ID tags. 2017-11-20 19:49:47 +00:00