redbear-power: add set_nice() syscall helper for nice/renice editor

This commit is contained in:
2026-07-06 23:42:25 +03:00
parent e13f09f258
commit 95fdc37e52
@@ -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())
}
}