From c1a3f6f3a3f92f243ee7b2e93896879e2a480d0f Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Mon, 2 Mar 2026 12:50:48 +0900 Subject: [PATCH] nproc: Reject quota with some schedulers --- src/uu/nproc/src/nproc.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/uu/nproc/src/nproc.rs b/src/uu/nproc/src/nproc.rs index 9edf21bf6..1e76f81df 100644 --- a/src/uu/nproc/src/nproc.rs +++ b/src/uu/nproc/src/nproc.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr sysconf +// spell-checker:ignore (ToDO) NPROCESSORS SCHED getscheduler nprocs numstr sched sysconf use clap::{Arg, ArgAction, Command}; use std::io::{Write, stdout}; @@ -67,7 +67,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } // the variable 'OMP_NUM_THREADS' doesn't exist // fallback to the regular CPU detection - Err(_) => available_parallelism(), + Err(_) => { + // ignore quota under some schedulers + #[cfg(any(target_os = "linux", target_os = "android"))] + match unsafe { libc::sched_getscheduler(0) } { + libc::SCHED_FIFO | libc::SCHED_RR | libc::SCHED_DEADLINE => num_cpus_all(), + _ => available_parallelism(), // include fallback for error + } + #[cfg(not(any(target_os = "linux", target_os = "android")))] + available_parallelism() + } } };