aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Pawel Stefaniak <pstef@FreeBSD.org>2020-05-28 13:19:41 +0000
committerPiotr Pawel Stefaniak <pstef@FreeBSD.org>2020-05-28 13:19:41 +0000
commit064f6f33e7eacb07dfdb3f65be459e7612f7e8c8 (patch)
tree0d1a59f9fceea2787dfa6223ad23ed11ff9af68f
parent0788d8fe94f0f2cffe3f312288dc1596d6277387 (diff)
downloadsrc-064f6f33e7eacb07dfdb3f65be459e7612f7e8c8.tar.gz
src-064f6f33e7eacb07dfdb3f65be459e7612f7e8c8.zip
MFS r361026
ps: extend the non-standard option -d (tree view) to work with -p Approved by: re (gjb)
Notes
Notes: svn path=/releng/11.4/; revision=361585
-rw-r--r--bin/ps/ps.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 80729bc97460..11642e850e79 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -490,7 +490,7 @@ main(int argc, char *argv[])
what = KERN_PROC_PGRP | showthreads;
flag = *pgrplist.l.pids;
nselectors = 0;
- } else if (pidlist.count == 1) {
+ } else if (pidlist.count == 1 && !descendancy) {
what = KERN_PROC_PID | showthreads;
flag = *pidlist.l.pids;
nselectors = 0;
@@ -528,6 +528,14 @@ main(int argc, char *argv[])
if ((kp == NULL && errno != ESRCH) || (kp != NULL && nentries < 0))
xo_errx(1, "%s", kvm_geterr(kd));
nkept = 0;
+ if (descendancy)
+ for (elem = 0; elem < pidlist.count; elem++)
+ for (i = 0; i < nentries; i++)
+ if (kp[i].ki_ppid == pidlist.l.pids[elem]) {
+ if (pidlist.count >= pidlist.maxcount)
+ expand_list(&pidlist);
+ pidlist.l.pids[pidlist.count++] = kp[i].ki_pid;
+ }
if (nentries > 0) {
if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL)
xo_errx(1, "malloc failed");