@@ -71,6 +71,20 @@ class Console::CommandDispatcher::Stdapi::Sys
71
71
"-c" => [ false , "Filter only child processes of the current shell" ] ,
72
72
"-h" => [ false , "Help menu." ] )
73
73
74
+ #
75
+ # Options for the 'pgrep' command.
76
+ #
77
+ @@pgrep_opts = Rex ::Parser ::Arguments . new (
78
+ "-S" => [ true , "Filter on process name" ] ,
79
+ "-U" => [ true , "Filter on user name" ] ,
80
+ "-A" => [ true , "Filter on architecture" ] ,
81
+ "-x" => [ false , "Filter for exact matches rather than regex" ] ,
82
+ "-s" => [ false , "Filter only SYSTEM processes" ] ,
83
+ "-c" => [ false , "Filter only child processes of the current shell" ] ,
84
+ "-l" => [ false , "Display process name with PID" ] ,
85
+ "-f" => [ false , "Display process path and args with PID (combine with -l)" ] ,
86
+ "-h" => [ false , "Help menu." ] )
87
+
74
88
#
75
89
# Options for the 'suspend' command.
76
90
#
@@ -418,9 +432,19 @@ def cmd_pkill_help
418
432
# Filters processes by name
419
433
#
420
434
def cmd_pgrep ( *args )
421
- if args . include? ( '-h' )
422
- cmd_pgrep_help
423
- return true
435
+ f_flag = false
436
+ l_flag = false
437
+
438
+ @@pgrep_opts . parse ( args ) do |opt , idx , val |
439
+ case opt
440
+ when '-h'
441
+ cmd_pgrep_help
442
+ return true
443
+ when '-l'
444
+ l_flag = true
445
+ when '-f'
446
+ f_flag = true
447
+ end
424
448
end
425
449
426
450
all_processes = client . sys . process . get_processes
@@ -430,10 +454,6 @@ def cmd_pgrep(*args)
430
454
return true
431
455
end
432
456
433
- # XXX fix Rex parser to properly handle adjacent short flags
434
- f_flag = args . include? ( '-f' ) || args . include? ( '-lf' ) || args . include? ( '-fl' )
435
- l_flag = args . include? ( '-l' ) || args . include? ( '-lf' ) || args . include? ( '-fl' )
436
-
437
457
processes . each do |p |
438
458
if l_flag
439
459
if f_flag
@@ -451,7 +471,7 @@ def cmd_pgrep(*args)
451
471
def cmd_pgrep_help
452
472
print_line ( "Usage: pgrep [ options ] pattern" )
453
473
print_line ( "Filter processes by name." )
454
- print_line @@ps_opts . usage
474
+ print_line @@pgrep_opts . usage
455
475
end
456
476
457
477
#
0 commit comments