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

Jesse Rosenstock jmr at google.com
Wed Mar 4 01:33:21 PST 2026


Here is a rebased version of the patch.

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   | 1 +
 toys/other/taskset.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/taskset.test b/tests/taskset.test
index c0bc900f86..db048a41f6 100755
--- a/tests/taskset.test
+++ b/tests/taskset.test
@@ -22,6 +22,7 @@
 testcmd 'set mask to first' '1 taskset -p $BASHPID | sed "s/.*: //"'
'1\n' '' ''
 testcmd 'set mask to last' '$LAST taskset -p $BASHPID | sed "s/.*:
//"' "$LAST\n" '' ''
 testcmd '-p 0 is current process' '1 taskset -p 0 | sed "s/.*: //"' '1\n' '' ''
+testcmd '--pid 0 is current process' '1 taskset --pid 0 | sed "s/.*:
//"' '1\n' '' ''
 toyonly testcmd 'no arguments shows current mask' '1 taskset' '1\n' '' ''
 testcmd 'run on first' '1 ps -o psr= $BASHPID | xargs' '0\n' '' ''
 testcmd 'run on last' '$LAST ps -o psr= $BASHPID | xargs' "$((CPUS-1))\n" '' ''


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: application/x-patch
Size: 1584 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20260304/84505557/attachment.bin>


More information about the Toybox mailing list