[git commit] chrt: support passing `-p 0` to operate on self
Denys Vlasenko
vda.linux at googlemail.com
Tue Oct 7 08:05:08 UTC 2025
commit: https://git.busybox.net/busybox/commit/?id=3cc24609520e3b4141aed4dec0de9eee64b7bdf6
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
Specifying a PID of 0 for the -p option of chrt would previously result
in a "number 0... not in range" error. Now, it means instead that the
calling process (i.e. chrt itself) should be operated on; this is to be
consistent with the behavior of util-linux's version of chrt.
function old new delta
chrt_main 462 474 +12
Signed-off-by: Zuo An <zuoan.penguin at gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
util-linux/chrt.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/util-linux/chrt.c b/util-linux/chrt.c
index 51d08584e..f64fa6aa6 100644
--- a/util-linux/chrt.c
+++ b/util-linux/chrt.c
@@ -17,9 +17,9 @@
//kbuild:lib-$(CONFIG_CHRT) += chrt.o
//usage:#define chrt_trivial_usage
-//usage: "-m | -p [PRIO] PID | [-rfobi] PRIO PROG ARGS"
+//usage: "-m | [-rfobi] { -p [PRIO] PID | PRIO PROG ARGS }"
//usage:#define chrt_full_usage "\n\n"
-//usage: "Change scheduling priority and class for a process\n"
+//usage: "Change scheduling priority and class (default RR) for a process\n"
//usage: "\n -m Show min/max priorities"
//usage: "\n -p Operate on PID"
//usage: "\n -r Set SCHED_RR class"
@@ -133,7 +133,14 @@ int chrt_main(int argc UNUSED_PARAM, char **argv)
pid_str = *argv;
}
/* else "-p PID", and *argv == NULL */
- pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1);
+ pid = xatoul_range(pid_str, 0, ((unsigned)(pid_t)ULONG_MAX) >> 1);
+
+ /* sched_{get,set}scheduler accept PID 0 to mean the calling process,
+ * but this is needed to display the actual PID like util-linux's chrt
+ */
+ if (pid == 0) {
+ pid = getpid();
+ }
} else {
priority = *argv++;
if (!*argv)
More information about the busybox-cvs
mailing list