From d632ad4aaef5a83c055ba42c409741f08a76bab0 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 5 Jul 2025 15:58:54 -0500 Subject: [PATCH] Minor cleanup, and add -a short option for --all --- toys/other/taskset.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/toys/other/taskset.c b/toys/other/taskset.c index 8ec726e9..80cc4c92 100644 --- a/toys/other/taskset.c +++ b/toys/other/taskset.c @@ -3,17 +3,17 @@ * Copyright 2012 Elie De Brauwer USE_TASKSET(NEWTOY(taskset, "<1^pa", TOYFLAG_USR|TOYFLAG_BIN)) -USE_NPROC(NEWTOY(nproc, "(all)", TOYFLAG_USR|TOYFLAG_BIN)) +USE_NPROC(NEWTOY(nproc, "a(all)", TOYFLAG_USR|TOYFLAG_BIN)) config NPROC bool "nproc" default y help - usage: nproc [--all] + usage: nproc [-a] Print number of processors. - --all Show all processors, not just ones this task can run on + -a Show all processors, not just ones this task can run on (--all) config TASKSET bool "taskset" @@ -41,7 +41,7 @@ config TASKSET #define sched_getaffinity(pid, size, cpuset) \ syscall(__NR_sched_getaffinity, (pid_t)pid, (size_t)size, (void *)cpuset) -static void do_taskset(pid_t pid, int quiet) +static void do_taskset(pid_t pid) { unsigned long *mask = (unsigned long *)toybuf; char *s, *failed = "failed to %s pid %d's affinity"; @@ -49,7 +49,7 @@ static void do_taskset(pid_t pid, int quiet) // loop through twice to display before/after affinity masks for (i=0; ; i++) { - if (!quiet) { + if (FLAG(p)) { if (-1 == sched_getaffinity(pid, sizeof(toybuf), (void *)mask)) perror_exit(failed, "get", pid); @@ -67,7 +67,7 @@ static void do_taskset(pid_t pid, int quiet) if (i || toys.optc < 2) return; - // Convert hex strong to mask[] bits + // Convert hex string to mask[] bits memset(toybuf, 0, sizeof(toybuf)); k = minof(strlen(s = *toys.optargs), 2*sizeof(toybuf)); s += k; @@ -87,7 +87,7 @@ static void do_taskset(pid_t pid, int quiet) static int task_callback(struct dirtree *new) { if (!new->parent) return DIRTREE_RECURSE|DIRTREE_SHUTUP|DIRTREE_PROC; - do_taskset(atoi(new->name), 0); + do_taskset(atoi(new->name)); return 0; } @@ -96,7 +96,7 @@ void taskset_main(void) { if (!FLAG(p)) { if (toys.optc < 2) error_exit("Needs 2 args"); - do_taskset(getpid(), 1); + do_taskset(getpid()); xexec(toys.optargs+1); } else { char *c, buf[33]; @@ -107,7 +107,7 @@ void taskset_main(void) if (FLAG(a)) { sprintf(buf, "/proc/%ld/task/", (long)pid); dirtree_read(buf, task_callback); - } else do_taskset(pid, 0); + } else do_taskset(pid); } } -- 2.39.5