From c9c0d42aae50b80cda27bd6131f315e57513be47 Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Sun, 28 Sep 2025 18:20:05 +0200 Subject: [PATCH] taskset: Add long options --all-tasks and --pid 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 c0bc900f..db048a41 100755 --- a/tests/taskset.test +++ b/tests/taskset.test @@ -22,6 +22,7 @@ testcmd 'set mask to all' '$MASK taskset -p $BASHPID | sed "s/.*: //"' "$MASK\n" 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 94044ebd..f095b0a1 100644 --- a/toys/other/taskset.c +++ b/toys/other/taskset.c @@ -2,7 +2,7 @@ * * Copyright 2012 Elie De Brauwer -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 @@ config TASKSET 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 -- 2.39.5