diff --git a/Base/usr/share/man/man1/ps.md b/Base/usr/share/man/man1/ps.md index af1c9f6858..e1b235ea26 100644 --- a/Base/usr/share/man/man1/ps.md +++ b/Base/usr/share/man/man1/ps.md @@ -5,7 +5,7 @@ ps - list currently running processes ## Synopsis ```**sh -$ ps [--version] [-a] [-A] [-e] [-f] [-p pid-list] [-q pid-list] [-t tty-list] [-u user-list] +$ ps [--version] [-a] [-A] [-e] [-f] [-p pid-list] [--ppid pid-list] [-q pid-list] [-t tty-list] [-u user-list] ``` ## Description @@ -19,6 +19,7 @@ For each process, print its PID (process ID), to which TTY it belongs, and invok * `-A` or `-e`: Consider all processes, not just those in the current TTY. * `-f`: Also print for each process: UID (as resolved username), PPID (parent PID), and STATE (Runnable, Sleeping, Selecting, Reading, etc.) * `-p pid-list`: Select processes matching any of the given PIDs. `pid-list` is a list of PIDs, separated by commas or spaces. +* `--ppid pid-list`: Select processes whose PPID matches any of the given PIDs. `pid-list` is a list of PIDs, separated by commas or spaces. * `-q pid-list`: Only consider the given PIDs, if they exist. Output the processes in the order provided by `pid-list`. `pid-list` is a list of PIDs, separated by commas or spaces. * `-t tty-list`: Select processes associated with any of the given terminals. `tty-list` is a list of short TTY names (e.g: `pts:0`) or the full TTY device paths, separated by commas or spaces. * `-u user-list`: Select processes matching any of the given UIDs. `user-list` is a list of UIDs or login names, separated by commas or spaces. diff --git a/Userland/Utilities/ps.cpp b/Userland/Utilities/ps.cpp index aea9f3453f..f3c68384ae 100644 --- a/Userland/Utilities/ps.cpp +++ b/Userland/Utilities/ps.cpp @@ -121,6 +121,7 @@ ErrorOr serenity_main(Main::Arguments arguments) bool provided_filtering_option = false; bool provided_quick_pid_list = false; Vector pid_list; + Vector parent_pid_list; Vector tty_list; Vector uid_list; @@ -136,6 +137,13 @@ ErrorOr 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 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())) {