mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
ps: Allow multiple filtering options to be used simultaneously
Previously, it was assumed that only one filtering option, such as `-u` or `-p` would be used at a time. With this PR, processes are now shown if they match any of the specified filters.
This commit is contained in:
parent
a758e27153
commit
aeb87d6e78
2 changed files with 16 additions and 11 deletions
|
@ -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`: Consider all processes that are associated with a TTY.
|
||||||
* `-A` or `-e`: Consider all processes, not just those in the current 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.)
|
* `-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.
|
* `-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
|
## Examples
|
||||||
|
|
||||||
|
|
|
@ -163,15 +163,20 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto& processes = all_processes.processes;
|
auto& processes = all_processes.processes;
|
||||||
|
|
||||||
// Filter
|
// Filter
|
||||||
if (!pid_list.is_empty()) {
|
if (!every_process_flag) {
|
||||||
processes.remove_all_matching([&](auto& process) { return !pid_list.contains_slow(process.pid); });
|
Vector<Core::ProcessStatistics> filtered_processes;
|
||||||
} else if (!uid_list.is_empty()) {
|
|
||||||
processes.remove_all_matching([&](auto& process) { return !uid_list.contains_slow(process.uid); });
|
for (auto const& process : processes) {
|
||||||
} else if (every_terminal_process_flag) {
|
// Default is to show processes from the current TTY
|
||||||
processes.remove_all_matching([&](auto& process) { return process.tty.is_empty(); });
|
if ((!provided_filtering_option && process.tty == this_pseudo_tty_name.bytes_as_string_view())
|
||||||
} else if (!every_process_flag) {
|
|| (!pid_list.is_empty() && pid_list.contains_slow(process.pid))
|
||||||
// Default is to show processes from the current TTY
|
|| (!uid_list.is_empty() && uid_list.contains_slow(process.uid))
|
||||||
processes.remove_all_matching([&](Core::ProcessStatistics& process) { return process.tty.view() != this_pseudo_tty_name.bytes_as_string_view(); });
|
|| (every_terminal_process_flag && !process.tty.is_empty())) {
|
||||||
|
filtered_processes.append(process);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
processes = move(filtered_processes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue