@@ -23,13 +23,15 @@ ErrorOr<int> serenity_main(Main::Arguments args)
23
23
bool display_number_of_matches = false ;
24
24
auto pid_delimiter = " \n " sv;
25
25
bool case_insensitive = false ;
26
+ bool list_process_name = false ;
26
27
bool invert_match = false ;
27
28
StringView pattern;
28
29
29
30
Core::ArgsParser args_parser;
30
31
args_parser.add_option (display_number_of_matches, " Suppress normal output and print the number of matching processes" , " count" , ' c' );
31
32
args_parser.add_option (pid_delimiter, " Set the string used to delimit multiple pids" , " delimiter" , ' d' , nullptr );
32
33
args_parser.add_option (case_insensitive, " Make matches case-insensitive" , " ignore-case" , ' i' );
34
+ args_parser.add_option (list_process_name, " List the process name in addition to its pid" , " list-name" , ' l' );
33
35
args_parser.add_option (invert_match, " Select non-matching lines" , " invert-match" , ' v' );
34
36
args_parser.add_positional_argument (pattern, " Process name to search for" , " process-name" );
35
37
args_parser.parse (args);
@@ -45,24 +47,27 @@ ErrorOr<int> serenity_main(Main::Arguments args)
45
47
46
48
auto all_processes = TRY (Core::ProcessStatisticsReader::get_all ());
47
49
48
- Vector<pid_t > matches;
49
- for (auto & it : all_processes.processes ) {
50
+ Vector<Core::ProcessStatistics > matches;
51
+ for (auto const & it : all_processes.processes ) {
50
52
auto result = re.match (it.name , PosixFlags::Global);
51
53
if (result.success ^ invert_match) {
52
- matches.append (it. pid );
54
+ matches.append (it);
53
55
}
54
56
}
55
57
56
58
if (display_number_of_matches) {
57
59
outln (" {}" , matches.size ());
58
60
} else {
59
- quick_sort (matches);
61
+ quick_sort (matches, []( auto const & a, auto const & b) { return a. pid < b. pid ; } );
60
62
auto displayed_at_least_one = false ;
61
63
for (auto & match : matches) {
62
64
if (displayed_at_least_one)
63
- out (" {}{}" sv, pid_delimiter, match);
64
- else
65
- out (" {}" sv, match);
65
+ out (" {}" sv, pid_delimiter);
66
+
67
+ out (" {}" sv, match.pid );
68
+
69
+ if (list_process_name)
70
+ out (" {}" sv, match.name );
66
71
67
72
displayed_at_least_one = true ;
68
73
}
0 commit comments