shell_rs/
nice.rs

1// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by General Public License that can be found
3// in the LICENSE file.
4
5use crate::error::Error;
6
7/// Get niceness of process.
8pub fn nice(pid: i32) -> Result<i32, Error> {
9    unsafe { nc::getpriority(nc::PRIO_PROCESS, pid).map_err(Into::into) }
10}
11
12#[cfg(test)]
13mod tests {
14    use super::nice;
15
16    #[test]
17    fn test_nice() {
18        let pid = unsafe { nc::getpid() };
19        let ret = nice(pid);
20        assert!(ret.is_ok());
21    }
22}