[Toybox] [PATCH] taskset: Add long options --all-tasks and --pid

Jesse Rosenstock jmr at google.com
Sun Sep 28 11:00:38 PDT 2025


These are supported by util-linux:
https://man7.org/linux/man-pages/man1/taskset.1.html#OPTIONS

No test was added for --all-tasks since there's no test for -a.
---
 tests/taskset.test   | 3 +++
 toys/other/taskset.c | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/tests/taskset.test b/tests/taskset.test
index 5732e23f0e..2080fc8277 100755
--- a/tests/taskset.test
+++ b/tests/taskset.test
@@ -22,6 +22,9 @@
 testing 'set mask to last' \
   '(taskset $LAST taskset -p 0 | sed "s/.*: //")' "$LAST\n" '' ''

+testing 'Long opt --pid' \
+  '(taskset 1 taskset --pid 0 | sed "s/.*: //")' '1\n' '' ''
+
 # alas procps-ng always says "-" for -o cpu so fetch the field from /proc
 testing 'run on first' \
   'X=$(taskset 1 cat /proc/self/stat); x() { echo ${39};}; x $X' \
diff --git a/toys/other/taskset.c b/toys/other/taskset.c
index 94044ebd07..f095b0a122 100644
--- a/toys/other/taskset.c
+++ b/toys/other/taskset.c
@@ -2,7 +2,7 @@
  *
  * Copyright 2012 Elie De Brauwer <eliedebrauwer at gmail.com>

-USE_TASKSET(NEWTOY(taskset, "^pa", TOYFLAG_USR|TOYFLAG_BIN))
+USE_TASKSET(NEWTOY(taskset, "^p(pid)a(all-tasks)", TOYFLAG_USR|TOYFLAG_BIN))
 USE_NPROC(NEWTOY(nproc, "a(all)", TOYFLAG_USR|TOYFLAG_BIN))

 config NPROC
@@ -28,8 +28,8 @@
     is allowed to run on. PID without a mask displays existing affinity.
     A PID of zero means the taskset process.

-    -p Set/get affinity of given PID instead of a new command
-    -a Set/get affinity of all threads of the PID
+    -p Set/get affinity of given PID instead of a new command (--pid)
+    -a Set/get affinity of all threads of the PID (--all-tasks)
 */

 #define FOR_taskset
-------------- next part --------------
A non-text attachment was scrubbed...
Name: taskset-long-opts.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20250928/c095f33a/attachment.bin>


More information about the Toybox mailing list