diff --git a/local/recipes/system/redbear-power/source/src/process.rs b/local/recipes/system/redbear-power/source/src/process.rs index aeff664920..c0ff82f59b 100644 --- a/local/recipes/system/redbear-power/source/src/process.rs +++ b/local/recipes/system/redbear-power/source/src/process.rs @@ -1987,3 +1987,23 @@ mod io_sort_unit_tests { assert_eq!(read_cpu_affinity(999_999_999), None); } } + + +/// Set the nice value of a process via setpriority(2). htop F7/F8 feature. +pub fn set_nice(pid: u32, nice: i32) -> Result<(), String> { + let n = nice.clamp(-20, 19); + #[cfg(target_os = "linux")] + unsafe { + // PRIO_PROCESS = 0, who = pid + if libc::setpriority(0, pid as u32, n) == 0 { + Ok(()) + } else { + Err(std::io::Error::last_os_error().to_string()) + } + } + #[cfg(not(target_os = "linux"))] + { + let _ = (pid, n); + Err("setpriority not supported on this platform".into()) + } +}