mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:18:11 +00:00
pkill: Allow signal names to be used with the -s
option
This commit is contained in:
parent
0d71db6721
commit
0621a83cb4
2 changed files with 23 additions and 3 deletions
|
@ -5,7 +5,7 @@ pkill - Signal processes based on name
|
||||||
## Synopsis
|
## Synopsis
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ pkill [--count] [--ignore-case] [--echo] [--signal number] [--uid uid-list] [--exact] <process-name>
|
$ pkill [--count] [--ignore-case] [--echo] [--signal signame] [--uid uid-list] [--exact] <process-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
@ -13,7 +13,7 @@ $ pkill [--count] [--ignore-case] [--echo] [--signal number] [--uid uid-list] [-
|
||||||
* `-c`, `--count`: Display the number of matching processes
|
* `-c`, `--count`: Display the number of matching processes
|
||||||
* `-i`, `--ignore-case`: Make matches case-insensitive
|
* `-i`, `--ignore-case`: Make matches case-insensitive
|
||||||
* `-e`, `--echo`: Display what is killed
|
* `-e`, `--echo`: Display what is killed
|
||||||
* `-s number`, `--signal number`: Signal number to send
|
* `-s signame`, `--signal signame`: Signal to send. The signal name or number may be used
|
||||||
* `-U uid-list`, `--uid uid-list`: Select only processes whose UID is in the given comma-separated list. Login name or numerical user ID may be used
|
* `-U uid-list`, `--uid uid-list`: Select only processes whose UID is in the given comma-separated list. Login name or numerical user ID may be used
|
||||||
* `-x`, `--exact`: Select only processes whose names match the given pattern exactly
|
* `-x`, `--exact`: Select only processes whose names match the given pattern exactly
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,27 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
args_parser.add_option(display_number_of_matches, "Display the number of matching processes", "count", 'c');
|
args_parser.add_option(display_number_of_matches, "Display the number of matching processes", "count", 'c');
|
||||||
args_parser.add_option(case_insensitive, "Make matches case-insensitive", "ignore-case", 'i');
|
args_parser.add_option(case_insensitive, "Make matches case-insensitive", "ignore-case", 'i');
|
||||||
args_parser.add_option(echo, "Display what is killed", "echo", 'e');
|
args_parser.add_option(echo, "Display what is killed", "echo", 'e');
|
||||||
args_parser.add_option(signal, "Signal number to send", "signal", 's', "number");
|
args_parser.add_option(Core::ArgsParser::Option {
|
||||||
|
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
||||||
|
.help_string = "Signal number to send. A signal name or number may be used",
|
||||||
|
.long_name = "signal",
|
||||||
|
.short_name = 's',
|
||||||
|
.value_name = "signame",
|
||||||
|
.accept_value = [&signal](StringView signal_string) {
|
||||||
|
if (signal_string.is_empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (is_ascii_alpha(signal_string[0]))
|
||||||
|
signal = getsignalbyname(&signal_string[0]);
|
||||||
|
else if (auto maybe_signal = signal_string.to_int(); maybe_signal.has_value())
|
||||||
|
signal = maybe_signal.value();
|
||||||
|
|
||||||
|
if (signal <= 0 || signal >= NSIG)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
args_parser.add_option(Core::ArgsParser::Option {
|
args_parser.add_option(Core::ArgsParser::Option {
|
||||||
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
||||||
.help_string = "Select only processes whose UID is in the given comma-separated list. Login name or numerical user ID may be used",
|
.help_string = "Select only processes whose UID is in the given comma-separated list. Login name or numerical user ID may be used",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue