diff options
Diffstat (limited to 'bin/ps')
-rw-r--r-- | bin/ps/Makefile | 2 | ||||
-rw-r--r-- | bin/ps/Makefile.depend | 6 | ||||
-rw-r--r-- | bin/ps/extern.h | 3 | ||||
-rw-r--r-- | bin/ps/fmt.c | 9 | ||||
-rw-r--r-- | bin/ps/keyword.c | 8 | ||||
-rw-r--r-- | bin/ps/nlist.c | 9 | ||||
-rw-r--r-- | bin/ps/print.c | 9 | ||||
-rw-r--r-- | bin/ps/ps.1 | 22 | ||||
-rw-r--r-- | bin/ps/ps.c | 69 | ||||
-rw-r--r-- | bin/ps/ps.h | 3 |
10 files changed, 62 insertions, 78 deletions
diff --git a/bin/ps/Makefile b/bin/ps/Makefile index 596aa57fd2df..23183e4e66b7 100644 --- a/bin/ps/Makefile +++ b/bin/ps/Makefile @@ -1,5 +1,3 @@ -# $FreeBSD$ -# @(#)Makefile 8.1 (Berkeley) 6/2/93 PACKAGE=runtime PROG= ps diff --git a/bin/ps/Makefile.depend b/bin/ps/Makefile.depend index eefffb37d491..521210d8ba8e 100644 --- a/bin/ps/Makefile.depend +++ b/bin/ps/Makefile.depend @@ -1,18 +1,14 @@ -# $FreeBSD$ # Autogenerated - do NOT edit! DIRDEPS = \ - gnu/lib/csu \ include \ include/xlocale \ lib/${CSU_DIR} \ lib/libc \ lib/libcompiler_rt \ - lib/libelf \ lib/libjail \ lib/libkvm \ - lib/libutil \ - lib/libxo \ + lib/libxo/libxo \ lib/msun \ diff --git a/bin/ps/extern.h b/bin/ps/extern.h index ea4362eeadd9..9d4630adfdd6 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -27,9 +27,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)extern.h 8.3 (Berkeley) 4/2/94 - * $FreeBSD$ */ struct kinfo; diff --git a/bin/ps/fmt.c b/bin/ps/fmt.c index c89ea78d7373..87e2e0f49a34 100644 --- a/bin/ps/fmt.c +++ b/bin/ps/fmt.c @@ -29,15 +29,6 @@ * SUCH DAMAGE. */ -#if 0 -#ifndef lint -static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94"; -#endif -#endif - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index e78cf984e455..82c08d3e75f1 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -29,14 +29,6 @@ * SUCH DAMAGE. */ -#if 0 -#ifndef lint -static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94"; -#endif /* not lint */ -#endif -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/time.h> #include <sys/resource.h> diff --git a/bin/ps/nlist.c b/bin/ps/nlist.c index 5ef56c9dfabc..8c6a4814e4d5 100644 --- a/bin/ps/nlist.c +++ b/bin/ps/nlist.c @@ -29,15 +29,6 @@ * SUCH DAMAGE. */ -#if 0 -#ifndef lint -static char sccsid[] = "@(#)nlist.c 8.4 (Berkeley) 4/2/94"; -#endif /* not lint */ -#endif - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/types.h> #include <sys/sysctl.h> diff --git a/bin/ps/print.c b/bin/ps/print.c index d4dbd9624011..fc6f7ab25428 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -29,15 +29,6 @@ * SUCH DAMAGE. */ -#if 0 -#ifndef lint -static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; -#endif /* not lint */ -#endif - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/time.h> #include <sys/resource.h> diff --git a/bin/ps/ps.1 b/bin/ps/ps.1 index 25373adb7d73..21def154ec00 100644 --- a/bin/ps/ps.1 +++ b/bin/ps/ps.1 @@ -26,10 +26,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)ps.1 8.3 (Berkeley) 4/18/94 -.\" $FreeBSD$ -.\" -.Dd June 27, 2020 +.Dd November 11, 2023 .Dt PS 1 .Os .Sh NAME @@ -40,6 +37,7 @@ .Op Fl -libxo .Op Fl aCcdefHhjlmrSTuvwXxZ .Op Fl O Ar fmt | Fl o Ar fmt +.Op Fl D Ar up | down | both .Op Fl G Ar gid Ns Op , Ns Ar gid Ns Ar ... .Op Fl J Ar jid Ns Op , Ns Ar jid Ns Ar ... .Op Fl M Ar core @@ -49,7 +47,7 @@ .Op Fl U Ar user Ns Op , Ns Ar user Ns Ar ... .Nm .Op Fl -libxo -.Op Fl L +.Fl L .Sh DESCRIPTION The .Nm @@ -65,7 +63,7 @@ will also display processes that do not have controlling terminals. .Pp A different set of processes can be selected for display by using any combination of the -.Fl a , G , J , p , T , t , +.Fl a , D , G , J , p , T , t , and .Fl U options. @@ -147,6 +145,18 @@ relative to each other. Note that this option has no effect if the .Dq command column is not the last column displayed. +.It Fl D +Expand the list of selected processes based on the process tree. +.Dq UP +will add the ancestor processes, +.Dq DOWN +will add the descendant processes, and +.Dq BOTH +will add both the ancestor and the descendant processes. +.Fl D +does not imply +.Fl d , +but works well with it. .It Fl e Display the environment as well. .It Fl f diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 89d90b78f2b0..cbee10c20d53 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -36,21 +36,6 @@ * ------+---------+---------+-------- + --------+---------+---------+---------* */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1990, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#if 0 -#ifndef lint -static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; -#endif /* not lint */ -#endif - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - #include <sys/param.h> #include <sys/jail.h> #include <sys/proc.h> @@ -114,7 +99,7 @@ static int needcomm; /* -o "command" */ static int needenv; /* -e */ static int needuser; /* -o "user" */ static int optfatal; /* Fatal error parsing some list-option. */ -static int pid_max; /* kern.max_pid */ +static int pid_max; /* kern.pid_max */ static enum sort { DEFAULT, SORTMEM, SORTCPU } sortby = DEFAULT; @@ -170,7 +155,7 @@ static char vfmt[] = "pid,state,time,sl,re,pagein,vsz,rss,lim,tsiz," "%cpu,%mem,command"; static char Zfmt[] = "label"; -#define PS_ARGS "AaCcde" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" +#define PS_ARGS "AaCcD:de" OPT_LAZY_f "G:gHhjJ:LlM:mN:O:o:p:rSTt:U:uvwXxZ" int main(int argc, char *argv[]) @@ -190,6 +175,8 @@ main(int argc, char *argv[]) int fwidthmin, fwidthmax; char errbuf[_POSIX2_LINE_MAX]; char fmtbuf[_POSIX2_LINE_MAX]; + enum { NONE = 0, UP = 1, DOWN = 2, BOTH = 1 | 2 } directions = NONE; + struct { int traversed; int initial; } pid_count; (void) setlocale(LC_ALL, ""); time(&now); /* Used by routines in print.c. */ @@ -264,6 +251,20 @@ main(int argc, char *argv[]) case 'c': cflag = 1; break; + case 'D': { + size_t len = strlen(optarg); + + if (len <= 2 && + strncasecmp(optarg, "up", len) == 0) + directions |= UP; + else if (len <= 4 && + strncasecmp(optarg, "down", len) == 0) + directions |= DOWN; + else if (len <= 4 && + strncasecmp(optarg, "both", len) == 0) + directions |= BOTH; + break; + } case 'd': descendancy = 1; break; @@ -504,7 +505,7 @@ main(int argc, char *argv[]) what = KERN_PROC_PGRP | showthreads; flag = *pgrplist.l.pids; nselectors = 0; - } else if (pidlist.count == 1 && !descendancy) { + } else if (pidlist.count == 1 && directions == NONE) { what = KERN_PROC_PID | showthreads; flag = *pidlist.l.pids; nselectors = 0; @@ -539,14 +540,33 @@ 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) + pid_count.initial = pidlist.count; + if (directions & DOWN) for (elem = 0; elem < pidlist.count; elem++) - for (i = 0; i < nentries; i++) + for (i = 0; i < nentries; i++) { + if (kp[i].ki_ppid == kp[i].ki_pid) + continue; 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; } + } + pid_count.traversed = pidlist.count; + if (directions & UP) + for (elem = 0; elem < pidlist.count; elem++) { + if (elem >= pid_count.initial && elem < pid_count.traversed) + continue; + for (i = 0; i < nentries; i++) { + if (kp[i].ki_ppid == kp[i].ki_pid) + continue; + if (kp[i].ki_pid == pidlist.l.pids[elem]) { + if (pidlist.count >= pidlist.maxcount) + expand_list(&pidlist); + pidlist.l.pids[pidlist.count++] = kp[i].ki_ppid; + } + } + } if (nentries > 0) { if ((kinfo = malloc(nentries * sizeof(*kinfo))) == NULL) xo_errx(1, "malloc failed"); @@ -1458,10 +1478,11 @@ usage(void) { #define SINGLE_OPTS "[-aCcde" OPT_LAZY_f "HhjlmrSTuvwXxZ]" - (void)xo_error("%s\n%s\n%s\n%s\n", - "usage: ps " SINGLE_OPTS " [-O fmt | -o fmt] [-G gid[,gid...]]", - " [-J jid[,jid...]] [-M core] [-N system]", + (void)xo_error("%s\n%s\n%s\n%s\n%s\n", + "usage: ps [--libxo] " SINGLE_OPTS " [-O fmt | -o fmt]", + " [-G gid[,gid...]] [-J jid[,jid...]] [-M core] [-N system]", " [-p pid[,pid...]] [-t tty[,tty...]] [-U user[,user...]]", - " ps [-L]"); + " [-D up | down | both]", + " ps [--libxo] -L"); exit(1); } diff --git a/bin/ps/ps.h b/bin/ps/ps.h index 03e38af9d517..521027427036 100644 --- a/bin/ps/ps.h +++ b/bin/ps/ps.h @@ -27,9 +27,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)ps.h 8.1 (Berkeley) 5/31/93 - * $FreeBSD$ */ #include <sys/queue.h> |