10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -978,6 +978,7 @@ dependencies = [
|
|||||||
"uu_lsmem",
|
"uu_lsmem",
|
||||||
"uu_mesg",
|
"uu_mesg",
|
||||||
"uu_mountpoint",
|
"uu_mountpoint",
|
||||||
|
"uu_renice",
|
||||||
"uu_rev",
|
"uu_rev",
|
||||||
"uu_setsid",
|
"uu_setsid",
|
||||||
"uucore",
|
"uucore",
|
||||||
@@ -1085,6 +1086,15 @@ dependencies = [
|
|||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uu_renice"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
"libc",
|
||||||
|
"uucore",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uu_rev"
|
name = "uu_rev"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
|
@@ -36,6 +36,7 @@ feat_common_core = [
|
|||||||
"lsmem",
|
"lsmem",
|
||||||
"mesg",
|
"mesg",
|
||||||
"mountpoint",
|
"mountpoint",
|
||||||
|
"renice",
|
||||||
"rev",
|
"rev",
|
||||||
"setsid",
|
"setsid",
|
||||||
]
|
]
|
||||||
@@ -82,6 +83,7 @@ lslocks = { optional = true, version = "0.0.1", package = "uu_lslocks", path = "
|
|||||||
lsmem = { optional = true, version = "0.0.1", package = "uu_lsmem", path = "src/uu/lsmem" }
|
lsmem = { optional = true, version = "0.0.1", package = "uu_lsmem", path = "src/uu/lsmem" }
|
||||||
mesg = { optional = true, version = "0.0.1", package = "uu_mesg", path = "src/uu/mesg" }
|
mesg = { optional = true, version = "0.0.1", package = "uu_mesg", path = "src/uu/mesg" }
|
||||||
mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", path = "src/uu/mountpoint" }
|
mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", path = "src/uu/mountpoint" }
|
||||||
|
renice = { optional = true, version = "0.0.1", package = "uu_renice", path = "src/uu/renice" }
|
||||||
rev = { optional = true, version = "0.0.1", package = "uu_rev", path = "src/uu/rev" }
|
rev = { optional = true, version = "0.0.1", package = "uu_rev", path = "src/uu/rev" }
|
||||||
setsid = { optional = true, version = "0.0.1", package = "uu_setsid", path ="src/uu/setsid" }
|
setsid = { optional = true, version = "0.0.1", package = "uu_setsid", path ="src/uu/setsid" }
|
||||||
|
|
||||||
|
17
src/uu/renice/Cargo.toml
Normal file
17
src/uu/renice/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "uu_renice"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
description = "renice ~ (uutils) Alter priority of running processes"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/renice.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "renice"
|
||||||
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { workspace = true }
|
||||||
|
libc = { workspace = true }
|
||||||
|
uucore = { workspace = true }
|
7
src/uu/renice/renice.md
Normal file
7
src/uu/renice/renice.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# renice
|
||||||
|
|
||||||
|
```
|
||||||
|
renice [--priority|--relative] priority [-g|-p|-u] identifier...
|
||||||
|
```
|
||||||
|
|
||||||
|
Alter priority of running processes
|
1
src/uu/renice/src/main.rs
Normal file
1
src/uu/renice/src/main.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uucore::bin!(uu_renice);
|
65
src/uu/renice/src/renice.rs
Normal file
65
src/uu/renice/src/renice.rs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// This file is part of the uutils util-linux package.
|
||||||
|
//
|
||||||
|
// For the full copyright and license information, please view the LICENSE
|
||||||
|
// file that was distributed with this source code.
|
||||||
|
|
||||||
|
use clap::{crate_version, Arg, Command};
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
use libc::PRIO_PROCESS;
|
||||||
|
use std::env;
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
use std::io::Error;
|
||||||
|
use std::process;
|
||||||
|
use uucore::{error::UResult, format_usage, help_about, help_usage};
|
||||||
|
|
||||||
|
const ABOUT: &str = help_about!("renice.md");
|
||||||
|
const USAGE: &str = help_usage!("renice.md");
|
||||||
|
|
||||||
|
#[uucore::main]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
|
let nice_value_str = matches.get_one::<String>("nice_value").unwrap(); // Retrieve as String
|
||||||
|
let nice_value = nice_value_str.parse::<i32>().unwrap_or_else(|_| {
|
||||||
|
eprintln!("Invalid nice value");
|
||||||
|
process::exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
let pid_str = matches.get_one::<String>("pid").unwrap(); // Retrieve as String
|
||||||
|
let pid = pid_str.parse::<i32>().unwrap_or_else(|_| {
|
||||||
|
eprintln!("Invalid PID");
|
||||||
|
process::exit(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: implement functionality on windows
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
if unsafe { libc::setpriority(PRIO_PROCESS, pid.try_into().unwrap(), nice_value) } == -1 {
|
||||||
|
eprintln!("Failed to set nice value: {}", Error::last_os_error());
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Nice value of process {} set to {}", pid, nice_value);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uu_app() -> Command {
|
||||||
|
Command::new(uucore::util_name())
|
||||||
|
.version(crate_version!())
|
||||||
|
.about(ABOUT)
|
||||||
|
.override_usage(format_usage(USAGE))
|
||||||
|
.infer_long_args(true)
|
||||||
|
.arg(
|
||||||
|
Arg::new("nice_value")
|
||||||
|
.value_name("NICE_VALUE")
|
||||||
|
.help("The new nice value for the process")
|
||||||
|
.required(true)
|
||||||
|
.index(1),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("pid")
|
||||||
|
.value_name("PID")
|
||||||
|
.help("The PID of the process")
|
||||||
|
.required(true)
|
||||||
|
.index(2),
|
||||||
|
)
|
||||||
|
}
|
12
tests/by-util/test_renice.rs
Normal file
12
tests/by-util/test_renice.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// This file is part of the uutils util-linux package.
|
||||||
|
//
|
||||||
|
// For the full copyright and license information, please view the LICENSE
|
||||||
|
// file that was distributed with this source code.
|
||||||
|
// spell-checker:ignore (words) symdir somefakedir
|
||||||
|
|
||||||
|
use crate::common::util::TestScenario;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_invalid_arg() {
|
||||||
|
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||||
|
}
|
@@ -33,6 +33,10 @@ mod test_blockdev;
|
|||||||
#[path = "by-util/test_ctrlaltdel.rs"]
|
#[path = "by-util/test_ctrlaltdel.rs"]
|
||||||
mod test_ctrlaltdel;
|
mod test_ctrlaltdel;
|
||||||
|
|
||||||
|
#[cfg(feature = "renice")]
|
||||||
|
#[path = "by-util/test_renice.rs"]
|
||||||
|
mod test_renice;
|
||||||
|
|
||||||
#[cfg(feature = "rev")]
|
#[cfg(feature = "rev")]
|
||||||
#[path = "by-util/test_rev.rs"]
|
#[path = "by-util/test_rev.rs"]
|
||||||
mod test_rev;
|
mod test_rev;
|
||||||
|
Reference in New Issue
Block a user