diff --git a/Base/usr/share/man/man1/ps.md b/Base/usr/share/man/man1/ps.md index 8bc29cc1e2..9911f3e2eb 100644 --- a/Base/usr/share/man/man1/ps.md +++ b/Base/usr/share/man/man1/ps.md @@ -18,9 +18,9 @@ For each process, print its PID (process ID), to which TTY it belongs, and invok * `-a`: Consider all processes that are associated with a TTY. * `-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`: Only consider the given PIDs, if they exist. `pid-list` is a list of PIDs, separated by commas or spaces. +* `-p pid-list`: Select processes matching 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. -* `-u user-list`: Only consider processes for the given users, if they exist. `user-list` is a list of UIDs or login names, 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. ## Examples diff --git a/Userland/Utilities/ps.cpp b/Userland/Utilities/ps.cpp index 6789a6e591..de96662530 100644 --- a/Userland/Utilities/ps.cpp +++ b/Userland/Utilities/ps.cpp @@ -163,15 +163,20 @@ ErrorOr serenity_main(Main::Arguments arguments) auto& processes = all_processes.processes; // Filter - if (!pid_list.is_empty()) { - processes.remove_all_matching([&](auto& process) { return !pid_list.contains_slow(process.pid); }); - } else if (!uid_list.is_empty()) { - processes.remove_all_matching([&](auto& process) { return !uid_list.contains_slow(process.uid); }); - } else if (every_terminal_process_flag) { - processes.remove_all_matching([&](auto& process) { return process.tty.is_empty(); }); - } else if (!every_process_flag) { - // Default is to show processes from the current TTY - processes.remove_all_matching([&](Core::ProcessStatistics& process) { return process.tty.view() != this_pseudo_tty_name.bytes_as_string_view(); }); + if (!every_process_flag) { + Vector filtered_processes; + + for (auto const& process : processes) { + // 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)) + || (!uid_list.is_empty() && uid_list.contains_slow(process.uid)) + || (every_terminal_process_flag && !process.tty.is_empty())) { + filtered_processes.append(process); + } + } + + processes = move(filtered_processes); } // Sort