From fab7b3c4f7535eb43ebb6fbe4fe39e9bce4d47db Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 15 Apr 2024 15:00:12 +0200 Subject: add -t to list threads --- px.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'px.c') diff --git a/px.c b/px.c index 6172ecb..aef25c0 100644 --- a/px.c +++ b/px.c @@ -22,6 +22,7 @@ #include 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) -- cgit 1.4.1