about summary refs log tree commit diff
path: root/px.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-04-15 15:00:12 +0200
committerLeah Neukirchen <leah@vuxu.org>2024-04-15 15:00:12 +0200
commitfab7b3c4f7535eb43ebb6fbe4fe39e9bce4d47db (patch)
treef863f0c17a9b6c4000fe6b9006f1e59e7bef04e5 /px.c
parent58246397d7e5898c886337502d089a84b3b1faa8 (diff)
downloadpx-master.tar.gz
px-master.tar.xz
px-master.zip
add -t to list threads HEAD master
Diffstat (limited to 'px.c')
-rw-r--r--px.c28
1 files changed, 15 insertions, 13 deletions
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)