Commit graph

36 commits

Author SHA1 Message Date
Liav A
5055883b9f Utilities/ps: Add process start time column in full format mode
Just like on Linux, we can easily print the process creation time. The
format of a printed time is either "hour:minute" if the process started
today, or "short_month_name:day_of_the_month" (for example, "Aug26").
2023-08-27 22:53:22 +02:00
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Tim Ledbetter
73a6f2e9ed ps: Add the -o option to specify a user-defined column format
This option allows the user to change which colums are displayed
by giving comma or space separated list of column format specifiers.

A column format specifier is of the form: `COLUMN_NAME[=COLUMN_TITLE]`.
Where `COLUMN_NAME` is any of: uid, pid, ppid, pgid, sid, state, tty,
or cmd. Specifying a `COLUMN_TITLE` will change the name shown in the
column header.

`COLUMN_TITLE` may be blank. If all given column titles
are blank, the header is omitted.
2023-07-19 11:21:59 +01:00
Tim Ledbetter
cdb15a20ff ps: Select user-specified processes only when the -q option is used
This fixes a logic bug which allowed processes not specified by the
user to be selected when the `-q` option was used. This caused the
program to crash when sorting processes into the correct order.
2023-07-19 11:21:59 +01:00
Tim Ledbetter
4e7e878606 ps: Add --ppid option to filter by parent PID 2023-07-11 13:02:08 +01:00
Tim Ledbetter
d3c5ae0860 ps: Add -t option to filter by TTY 2023-07-11 13:02:08 +01:00
Tim Ledbetter
aeb87d6e78 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.
2023-07-11 13:02:08 +01:00
Tim Ledbetter
a758e27153 ps: Disallow using -q with any other filtering options
This matches the behavior of `ps` on Linux.
2023-07-11 13:02:08 +01:00
Sam Atkins
be71ccb690 ps: Add -u option, to list processes associated with specified users 2023-05-16 12:54:18 +02:00
Sam Atkins
cf998bc082 ps: Perform filtering step before the output loop
Previously we did some of the filtering before the loop, and some inside
it, which made things awkward to reason about. This also lets us avoid
generating a TTY string for each process unless there's a column for it.
2023-05-16 12:54:18 +02:00
Sam Atkins
3aff3c610a ps: Add -p option, and distinguish it from -q 2023-05-16 12:54:18 +02:00
Sam Atkins
45c429853a ps: Allow -q option multiple times, and separated by spaces or commas
Several differences here:
- Passing `-q` multiple times will add them together, instead of the
  last one overwriting the previous ones.
- `-q` PIDs can be separated by commas as well as spaces.
- We check that the PIDs are integers while parsing the arguments,
  instead of later on.

The "parse a list of things as an option" is extracted into a helper
function, because we're going to want the same logic for `-g`, `-G`,
`-p`, `-t`, `-u`, and `-U`.
2023-05-16 12:54:18 +02:00
Sam Atkins
a6e701a67b ps: Add the -a option, to list all processes associated with terminals 2023-05-16 12:54:18 +02:00
Sam Atkins
afb55d9fd8 ps: Add the -A option
This is identical to our existing `-e` option, but both are required by
POSIX.
2023-05-16 12:54:18 +02:00
Sam Atkins
02ee93d6c9 ps: Use Optional for column indices, instead of -1 meaning "not present" 2023-05-16 12:54:18 +02:00
Sam Atkins
e6f7b828c3 ps: Ensure columns capacity in advance
Also use unchecked_append() in a couple of other places where we can.
2023-05-16 12:54:18 +02:00
Sam Atkins
2b02c58cd3 ps: Migrate from DeprecatedString to String 2023-05-16 12:54:18 +02:00
Sam Atkins
61552415a3 ps: Use Core::System::fstat() 2023-05-16 12:54:18 +02:00
Tim Schumacher
8940f2da7f LibCore: Use Core::Stream for ProcessStatisticsReader 2022-12-10 11:49:24 +00:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Liav A
9d1ba0e6ad Utilities: Use new global variables at /sys/kernel/ directory 2022-10-25 15:33:34 -06:00
Thomas Symalla
77add584fa Userland: Fix crash when inputting non-tty device into ps
This PR aims to fix #13299 by avoiding assertion failure
while trying to determine the pseudo tty when inputting
any non-tty device device into ps.
2022-04-02 21:49:16 +02:00
Liav A
d7c7e6e496 Utilities/ps: Don't assume the kernel can provide real TTY paths 2022-03-26 11:01:49 +01:00
Brian Gianforcaro
cf4fa936be Everywhere: Use default execpromises argument for Core::System::pledge 2021-11-28 08:04:57 +01:00
Andreas Kling
e6579e7029 ps: Port to LibMain :^) 2021-11-23 15:44:59 +01:00
Peter Elliott
7283b0b214 Utilities: Show PGID and SID in ps -f 2021-10-17 22:18:48 +02:00
Mahmoud Mandour
ac7c83689b ps: Sort using input order in case of -q
Now the output of `ps -q <list>` is sorted according to the order the
user specified.
2021-08-28 15:08:00 +04:30
Mahmoud Mandour
259ecb3d11 ps: Select specific processes by their PIDs
This adds a `-q` option, which expects a comma-separated list of PIDs as
a value. On using it, only the processes associated with the supplied
PIDs are output.
2021-08-28 15:08:00 +04:30
Tom
7e77a2ec40 Everywhere: Improve CPU usage calculation
As threads come and go, we can't simply account for how many time
slices the threads at any given point may have been using. We need to
also account for threads that have since disappeared. This means we
also need to track how many time slices we have expired globally.

However, because this doesn't account for context switches outside of
the system timer tick values may still be under-reported. To solve this
we will need to track more accurate time information on each context
switch.

This also fixes top's cpu usage calculation which was still based on
the number of context switches.

Fixes #6473
2021-07-18 22:08:26 +02:00
Gunnar Beutner
bc174b0fd0 Utilities: Make sure columns for ps are properly aligned
This updates ps so that it calculates the ideal column width instead
of relying on hard-coded values. Previously the STATE column was too
small to fit the state for "FinalizerTask".
2021-06-03 17:53:59 +02:00
Linus Groh
f5c35fccca Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
Linus Groh
1eb048bed0 Userland: Remove a bunch of unused includes
As reported by CLion.
2021-05-31 18:01:53 +01:00
Andreas Kling
873eb47d2b ps: Sort output by PID :^) 2021-05-23 11:26:19 +02:00
Andreas Kling
a1e133cc6b LibCore: Make ProcessStatisticsReader return results in a Vector
The HashMap API was overkill and made using this less ergonomic than
it should be.
2021-05-23 11:10:15 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
ececac65c2 Userland: Move command-line utilities to Userland/Utilities/ 2021-01-12 12:04:09 +01:00
Renamed from Userland/ps.cpp (Browse further)