diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-10-07 08:39:54 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-10-07 10:05:08 +0200 |
| commit | 3cc24609520e3b4141aed4dec0de9eee64b7bdf6 (patch) | |
| tree | f3019f4a952a0137235dc0c09fb103fe805ca3e1 /util-linux | |
| parent | 552003dbd6f9e8d8adc55d969e63b9dedcbed726 (diff) | |
| download | busybox-w32-3cc24609520e3b4141aed4dec0de9eee64b7bdf6.tar.gz busybox-w32-3cc24609520e3b4141aed4dec0de9eee64b7bdf6.tar.bz2 busybox-w32-3cc24609520e3b4141aed4dec0de9eee64b7bdf6.zip | |
chrt: support passing `-p 0` to operate on self
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@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/chrt.c | 13 |
1 files 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 @@ | |||
| 17 | //kbuild:lib-$(CONFIG_CHRT) += chrt.o | 17 | //kbuild:lib-$(CONFIG_CHRT) += chrt.o |
| 18 | 18 | ||
| 19 | //usage:#define chrt_trivial_usage | 19 | //usage:#define chrt_trivial_usage |
| 20 | //usage: "-m | -p [PRIO] PID | [-rfobi] PRIO PROG ARGS" | 20 | //usage: "-m | [-rfobi] { -p [PRIO] PID | PRIO PROG ARGS }" |
| 21 | //usage:#define chrt_full_usage "\n\n" | 21 | //usage:#define chrt_full_usage "\n\n" |
| 22 | //usage: "Change scheduling priority and class for a process\n" | 22 | //usage: "Change scheduling priority and class (default RR) for a process\n" |
| 23 | //usage: "\n -m Show min/max priorities" | 23 | //usage: "\n -m Show min/max priorities" |
| 24 | //usage: "\n -p Operate on PID" | 24 | //usage: "\n -p Operate on PID" |
| 25 | //usage: "\n -r Set SCHED_RR class" | 25 | //usage: "\n -r Set SCHED_RR class" |
| @@ -133,7 +133,14 @@ int chrt_main(int argc UNUSED_PARAM, char **argv) | |||
| 133 | pid_str = *argv; | 133 | pid_str = *argv; |
| 134 | } | 134 | } |
| 135 | /* else "-p PID", and *argv == NULL */ | 135 | /* else "-p PID", and *argv == NULL */ |
| 136 | pid = xatoul_range(pid_str, 1, ((unsigned)(pid_t)ULONG_MAX) >> 1); | 136 | pid = xatoul_range(pid_str, 0, ((unsigned)(pid_t)ULONG_MAX) >> 1); |
| 137 | |||
| 138 | /* sched_{get,set}scheduler accept PID 0 to mean the calling process, | ||
| 139 | * but this is needed to display the actual PID like util-linux's chrt | ||
| 140 | */ | ||
| 141 | if (pid == 0) { | ||
| 142 | pid = getpid(); | ||
| 143 | } | ||
| 137 | } else { | 144 | } else { |
| 138 | priority = *argv++; | 145 | priority = *argv++; |
| 139 | if (!*argv) | 146 | if (!*argv) |
