mirror of
https://github.com/uutils/procps.git
synced 2026-06-10 16:14:00 -07:00
pkill: Support --inverse
pkill --help doesn't list this option, but it is listed in the manpage (and does work). Unlike pgrep, the short option '-v' doesn't exists for pkill though.
This commit is contained in:
@@ -36,6 +36,7 @@ struct Settings {
|
||||
exact: bool,
|
||||
full: bool,
|
||||
ignore_case: bool,
|
||||
inverse: bool,
|
||||
newest: bool,
|
||||
oldest: bool,
|
||||
older: Option<u64>,
|
||||
@@ -64,6 +65,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||
exact: matches.get_flag("exact"),
|
||||
full: matches.get_flag("full"),
|
||||
ignore_case: matches.get_flag("ignore-case"),
|
||||
inverse: matches.get_flag("inverse"),
|
||||
newest: matches.get_flag("newest"),
|
||||
oldest: matches.get_flag("oldest"),
|
||||
parent: matches
|
||||
@@ -235,11 +237,12 @@ fn collect_matched_pids(settings: &Settings) -> Vec<ProcessInformation> {
|
||||
_ => true,
|
||||
};
|
||||
|
||||
if run_state_matched
|
||||
if (run_state_matched
|
||||
&& pattern_matched
|
||||
&& tty_matched
|
||||
&& older_matched
|
||||
&& parent_matched
|
||||
&& parent_matched)
|
||||
^ settings.inverse
|
||||
{
|
||||
tmp_vec.push(pid);
|
||||
}
|
||||
@@ -343,12 +346,13 @@ pub fn uu_app() -> Command {
|
||||
.about(ABOUT)
|
||||
.override_usage(format_usage(USAGE))
|
||||
.args_override_self(true)
|
||||
.group(ArgGroup::new("oldest_newest").args(["oldest", "newest"]))
|
||||
.group(ArgGroup::new("oldest_newest").args(["oldest", "newest", "inverse"]))
|
||||
.args([
|
||||
// arg!(-<sig> "signal to send (either number or name)"),
|
||||
arg!(-H --"require-handler" "match only if signal handler is present"),
|
||||
// arg!(-q --queue <value> "integer value to be sent with the signal"),
|
||||
arg!(-e --echo "display what is killed"),
|
||||
arg!(--inverse "negates the matching"),
|
||||
arg!(-c --count "count of matching processes"),
|
||||
arg!(-f --full "use full process name to match"),
|
||||
// arg!(-g --pgroup <PGID> "match listed process group IDs")
|
||||
|
||||
@@ -44,6 +44,17 @@ fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_inverse() {
|
||||
new_ucmd!()
|
||||
.arg("-0")
|
||||
.arg("--inverse")
|
||||
.arg("NONEXISTENT")
|
||||
.fails()
|
||||
.stderr_contains("Permission denied");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_help() {
|
||||
|
||||
Reference in New Issue
Block a user