1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +00:00

ps: Add the -a option, to list all processes associated with terminals

This commit is contained in:
Sam Atkins 2023-05-14 13:44:40 +01:00 committed by Andreas Kling
parent afb55d9fd8
commit a6e701a67b
2 changed files with 11 additions and 2 deletions

View file

@ -5,7 +5,7 @@ ps - list currently running processes
## Synopsis ## Synopsis
```**sh ```**sh
$ ps [--version] [-A] [-e] [-f] [-q pid-list] $ ps [--version] [-a] [-A] [-e] [-f] [-q pid-list]
``` ```
## Description ## Description
@ -15,6 +15,7 @@ For each process, print its PID (process ID), to which TTY it belongs, and invok
## Options ## Options
* `-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.)
* `-q pid-list`: Only consider the given PIDs, if they exist. * `-q pid-list`: Only consider the given PIDs, if they exist.

View file

@ -54,10 +54,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}; };
bool every_process_flag = false; bool every_process_flag = false;
bool every_terminal_process_flag = false;
bool full_format_flag = false; bool full_format_flag = false;
StringView pid_list; StringView pid_list;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.add_option(every_terminal_process_flag, "Show every process associated with terminals", nullptr, 'a');
args_parser.add_option(every_process_flag, "Show every process", nullptr, 'A'); args_parser.add_option(every_process_flag, "Show every process", nullptr, 'A');
args_parser.add_option(every_process_flag, "Show every process (Equivalent to -A)", nullptr, 'e'); args_parser.add_option(every_process_flag, "Show every process (Equivalent to -A)", nullptr, 'e');
args_parser.add_option(full_format_flag, "Full format", nullptr, 'f'); args_parser.add_option(full_format_flag, "Full format", nullptr, 'f');
@ -140,8 +142,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
for (auto const& process : processes) { for (auto const& process : processes) {
auto tty = TRY(String::from_deprecated_string(process.tty)); auto tty = TRY(String::from_deprecated_string(process.tty));
if (!every_process_flag && tty != this_pseudo_tty_name) if (every_process_flag) {
// Don't skip any.
} else if (every_terminal_process_flag) {
if (tty.is_empty())
continue; continue;
} else if (tty != this_pseudo_tty_name) {
continue;
}
Vector<String> row; Vector<String> row;
TRY(row.try_resize(columns.size())); TRY(row.try_resize(columns.size()));