mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
pkill: Add -c
option to print the number of matches
This commit is contained in:
parent
6753cf8b20
commit
caa7edff92
1 changed files with 7 additions and 5 deletions
|
@ -23,12 +23,14 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
TRY(Core::System::unveil("/etc/passwd", "r"));
|
||||
TRY(Core::System::unveil(nullptr, nullptr));
|
||||
|
||||
bool display_number_of_matches;
|
||||
bool case_insensitive = false;
|
||||
bool echo = false;
|
||||
StringView pattern;
|
||||
int signal = SIGTERM;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(display_number_of_matches, "Print the number of matching processes", "count", 'c');
|
||||
args_parser.add_option(case_insensitive, "Make matches case-insensitive", nullptr, 'i');
|
||||
args_parser.add_option(echo, "Display what is killed", "echo", 'e');
|
||||
args_parser.add_option(signal, "Signal number to send", "signal", 's', "number");
|
||||
|
@ -55,10 +57,6 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
}
|
||||
}
|
||||
|
||||
if (matched_processes.is_empty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (auto& process : matched_processes) {
|
||||
auto result = Core::System::kill(process.pid, signal);
|
||||
if (result.is_error())
|
||||
|
@ -66,5 +64,9 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
else if (echo)
|
||||
outln("{} killed (pid {})", process.name, process.pid);
|
||||
}
|
||||
return 0;
|
||||
|
||||
if (display_number_of_matches)
|
||||
outln("{}", matched_processes.size());
|
||||
|
||||
return matched_processes.is_empty() ? 1 : 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue