pidof: Add -S option to specify a pid separator
This is useful for commands which expect a comma-separated list of pids.
This commit is contained in:
parent
8be7b16c42
commit
fac6c6c554
Notes:
sideshowbarker
2024-07-17 23:00:03 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/fac6c6c554 Pull-request: https://github.com/SerenityOS/serenity/pull/18823
1 changed files with 7 additions and 1 deletions
|
@ -17,6 +17,7 @@ struct Options {
|
|||
bool single_shot { false };
|
||||
Optional<pid_t> pid_to_omit;
|
||||
StringView process_name;
|
||||
StringView pid_separator { " "sv };
|
||||
};
|
||||
|
||||
static ErrorOr<int> pid_of(Options const& options)
|
||||
|
@ -29,7 +30,11 @@ static ErrorOr<int> pid_of(Options const& options)
|
|||
if (it.name != options.process_name || options.pid_to_omit == it.pid)
|
||||
continue;
|
||||
|
||||
out(displayed_at_least_one ? " {}"sv : "{}"sv, it.pid);
|
||||
if (displayed_at_least_one)
|
||||
out("{}{}"sv, options.pid_separator, it.pid);
|
||||
else
|
||||
out("{}"sv, it.pid);
|
||||
|
||||
displayed_at_least_one = true;
|
||||
|
||||
if (options.single_shot)
|
||||
|
@ -75,6 +80,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
|
|||
},
|
||||
});
|
||||
args_parser.add_option(options.single_shot, "Only return one pid", nullptr, 's');
|
||||
args_parser.add_option(options.pid_separator, "Use `separator` to separate multiple pids", nullptr, 'S', "separator");
|
||||
args_parser.add_positional_argument(options.process_name, "Process name to search for", "process-name");
|
||||
|
||||
args_parser.parse(args);
|
||||
|
|
Loading…
Add table
Reference in a new issue