mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
ps: Add the -a
option, to list all processes associated with terminals
This commit is contained in:
parent
afb55d9fd8
commit
a6e701a67b
Notes:
sideshowbarker
2024-07-17 18:49:10 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/a6e701a67b Pull-request: https://github.com/SerenityOS/serenity/pull/18856 Reviewed-by: https://github.com/awesomekling
2 changed files with 11 additions and 2 deletions
|
@ -5,7 +5,7 @@ ps - list currently running processes
|
|||
## Synopsis
|
||||
|
||||
```**sh
|
||||
$ ps [--version] [-A] [-e] [-f] [-q pid-list]
|
||||
$ ps [--version] [-a] [-A] [-e] [-f] [-q pid-list]
|
||||
```
|
||||
|
||||
## Description
|
||||
|
@ -15,6 +15,7 @@ For each process, print its PID (process ID), to which TTY it belongs, and invok
|
|||
|
||||
## Options
|
||||
|
||||
* `-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.)
|
||||
* `-q pid-list`: Only consider the given PIDs, if they exist.
|
||||
|
|
|
@ -54,10 +54,12 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
};
|
||||
|
||||
bool every_process_flag = false;
|
||||
bool every_terminal_process_flag = false;
|
||||
bool full_format_flag = false;
|
||||
StringView pid_list;
|
||||
|
||||
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 (Equivalent to -A)", nullptr, 'e');
|
||||
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) {
|
||||
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;
|
||||
} else if (tty != this_pseudo_tty_name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vector<String> row;
|
||||
TRY(row.try_resize(columns.size()));
|
||||
|
|
Loading…
Reference in a new issue