diff options
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | px.1 | 9 | ||||
-rw-r--r-- | px.c | 28 |
3 files changed, 26 insertions, 19 deletions
diff --git a/README b/README index da89814..cd6bee8 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME px – report details on matching processes SYNOPSIS - px [-f] PATTERNS ... + px [-f] [-t] PATTERNS ... DESCRIPTION px searches the process list for processes matching any of the patterns @@ -18,12 +18,14 @@ DESCRIPTION -f Search the whole command line, including arguments. + -t Print each thread, not just each process. + EXIT STATUS The px utility returns 0 when a process was found, 1 if no process was found, and 2 when other errors occured. SEE ALSO - ps(1), pgrep(2) + pgrep(1), ps(1) AUTHORS Leah Neukirchen <leah@vuxu.org> @@ -36,4 +38,4 @@ LICENSE http://creativecommons.org/publicdomain/zero/1.0/ -Void Linux May 8, 2023 Void Linux +Void Linux April 15, 2024 Void Linux diff --git a/px.1 b/px.1 index d446cd0..c1cd7db 100644 --- a/px.1 +++ b/px.1 @@ -1,4 +1,4 @@ -.Dd May 08, 2023 +.Dd April 15, 2024 .Dt PX 1 .Os .Sh NAME @@ -7,6 +7,7 @@ .Sh SYNOPSIS .Nm .Op Fl f +.Op Fl t .Ar PATTERNS ... .Sh DESCRIPTION .Nm @@ -25,6 +26,8 @@ The options are as follows: .Bl -tag -width Ds .It Fl f Search the whole command line, including arguments. +.It Fl t +Print each thread, not just each process. .El .Sh EXIT STATUS The @@ -33,8 +36,8 @@ utility returns 0 when a process was found, 1 if no process was found, and 2 when other errors occured. .Sh SEE ALSO -.Xr ps 1 , -.Xr pgrep 2 +.Xr pgrep 1 , +.Xr ps 1 .Sh AUTHORS .An Leah Neukirchen Aq Mt leah@vuxu.org .Sh LICENSE diff --git a/px.c b/px.c index 6172ecb..aef25c0 100644 --- a/px.c +++ b/px.c @@ -22,6 +22,7 @@ #include <libproc2/stat.h> int fflag; +int tflag; static void print_human(intmax_t i) @@ -109,26 +110,27 @@ main(int argc, char *argv[]) exit(2); } + int matched = 0; + + int c; + while ((c = getopt(argc, argv, "tf")) != -1) + switch (c) { + case 't': tflag = 1; break; + case 'f': fflag = 1; break; + default: + fprintf(stderr, + "Usage: %s [-f] [PATTERN...]\n", argv[0]); + exit(2); + } + struct pids_fetch *reap = procps_pids_reap(Pids_info, - PIDS_FETCH_TASKS_ONLY); + tflag == 0 ? PIDS_FETCH_TASKS_ONLY : PIDS_FETCH_THREADS_TOO); if (!reap) { fprintf(stderr, "failed to run procps_pids_reap: %s\n", strerror(errno)); exit(2); } - int matched = 0; - - int c; - while ((c = getopt(argc, argv, "f")) != -1) - switch (c) { - case 'f': fflag = 1; break; - default: - fprintf(stderr, - "Usage: %s [-f] [PATTERN...]\n", argv[0]); - exit(2); - } - int total_procs = reap->counts->total; for (int i = 0; i < total_procs; i++) { #define PIDS_GETCHR(e) PIDS_VAL(EU_ ## e, s_ch, reap->stacks[i], Pids_info) |