diff options
author | Mahmoud Mandour <ma.mandourr@gmail.com> | 2021-08-28 11:13:15 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-08-28 15:08:00 +0430 |
commit | ac7c83689bd4383b83574647c73507be4715f068 (patch) | |
tree | 79a5c2b02a2db032730f08b336e1e5a212f72044 /Userland | |
parent | 259ecb3d11e4f88da4f672d2eec1ec0deebcf01a (diff) | |
download | serenity-ac7c83689bd4383b83574647c73507be4715f068.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Utilities/ps.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Utilities/ps.cpp b/Userland/Utilities/ps.cpp index 8eb458e9b4..b685ad59ac 100644 --- a/Userland/Utilities/ps.cpp +++ b/Userland/Utilities/ps.cpp @@ -110,9 +110,14 @@ int main(int argc, char** argv) } processes.remove_all_matching([&](auto& a) { return selected_pids.find(a.pid) == selected_pids.end(); }); - } - quick_sort(processes, [](auto& a, auto& b) { return a.pid < b.pid; }); + auto processes_sort_predicate = [&selected_pids](auto& a, auto& b) { + return selected_pids.find_first_index(a.pid).value() < selected_pids.find_first_index(b.pid).value(); + }; + quick_sort(processes, processes_sort_predicate); + } else { + quick_sort(processes, [](auto& a, auto& b) { return a.pid < b.pid; }); + } Vector<Vector<String>> rows; rows.ensure_capacity(1 + processes.size()); |