1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

ps: Add --ppid option to filter by parent PID

This commit is contained in:
Tim Ledbetter 2023-07-10 20:47:55 +01:00 committed by Sam Atkins
parent d3c5ae0860
commit 4e7e878606
2 changed files with 11 additions and 1 deletions

View file

@ -121,6 +121,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
bool provided_filtering_option = false;
bool provided_quick_pid_list = false;
Vector<pid_t> pid_list;
Vector<pid_t> parent_pid_list;
Vector<DeprecatedString> tty_list;
Vector<uid_t> uid_list;
@ -136,6 +137,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
warnln("Could not parse '{}' as a PID.", pid_string);
return pid;
}));
args_parser.add_option(make_list_option(parent_pid_list, "Show processes with a matching PPID. (Comma- or space-separated list.)", "ppid", {}, "pid-list", [&](StringView pid_string) {
provided_filtering_option = true;
auto pid = pid_string.to_int();
if (!pid.has_value())
warnln("Could not parse '{}' as a PID.", pid_string);
return pid;
}));
args_parser.add_option(make_list_option(pid_list, "Show processes with a matching PID. (Comma- or space-separated list.) Processes will be listed in the order given.", nullptr, 'q', "pid-list", [&](StringView pid_string) {
provided_quick_pid_list = true;
auto pid = pid_string.to_int();
@ -217,6 +225,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// Default is to show processes from the current TTY
if ((!provided_filtering_option && process.tty == this_pseudo_tty_name.bytes_as_string_view())
|| (!pid_list.is_empty() && pid_list.contains_slow(process.pid))
|| (!parent_pid_list.is_empty() && parent_pid_list.contains_slow(process.ppid))
|| (!uid_list.is_empty() && uid_list.contains_slow(process.uid))
|| (!tty_list.is_empty() && tty_list.contains_slow(process.tty))
|| (every_terminal_process_flag && !process.tty.is_empty())) {