ps: add -q/q/--quick-pid option

This commit introduces a new option q/-q/--quick-pid
to the 'ps' command. The option does a similar job
to the p/-p/--pid option (i.e. selection of PIDs
listed in the comma separated list that follows
the option), but the new option is optimized
for speed.
In cases where users only need to specify a list
of PIDs to be shown and don't need other selection
options, forest type output and sorting options,
the new option is recommended as it decreases
the initial processing delay by avoiding reading
the necessary information from all the processes
running on the system and by simplifying
the internal filtering logic.
This commit is contained in:
Jaromir Capik
2014-07-10 21:14:02 +02:00
parent 6cd8691720
commit e751606fcc
6 changed files with 131 additions and 4 deletions

View File

@ -426,6 +426,14 @@ static const char *parse_sysv_option(void){
if(err) return err;
selection_list->typecode = SEL_PID;
return NULL; /* can't have any more options */
case 'q': /* end */
trace("-q quick select by PID.\n");
arg=get_opt_arg();
if(!arg) return "List of process IDs must follow -q.";
err=parse_list(arg, parse_pid);
if(err) return err;
selection_list->typecode = SEL_PID_QUICK;
return NULL; /* can't have any more options */
#if 0
case 'r':
trace("-r some Digital Unix thing about warnings...\n");
@ -696,6 +704,14 @@ static const char *parse_bsd_option(void){
if(err) return err;
selection_list->typecode = SEL_PID;
return NULL; /* can't have any more options */
case 'q': /* end */
trace("q Quick select by process ID\n");
arg=get_opt_arg();
if(!arg) return "List of process IDs must follow q.";
err=parse_list(arg, parse_pid);
if(err) return err;
selection_list->typecode = SEL_PID_QUICK;
return NULL; /* can't have any more options */
case 'r':
trace("r select running processes\n");
running_only = 1;
@ -820,6 +836,7 @@ static const char *parse_gnu_option(void){
{"noheadings", &&case_noheadings},
{"pid", &&case_pid},
{"ppid", &&case_ppid},
{"quick-pid", &&case_pid_quick},
{"rows", &&case_rows},
{"sid", &&case_sid},
{"sort", &&case_sort},
@ -949,6 +966,14 @@ static const char *parse_gnu_option(void){
if(err) return err;
selection_list->typecode = SEL_PID;
return NULL;
case_pid_quick:
trace("--quick-pid\n");
arg = grab_gnu_arg();
if(!arg) return "List of process IDs must follow --quick-pid.";
err=parse_list(arg, parse_pid);
if(err) return err;
selection_list->typecode = SEL_PID_QUICK;
return NULL;
case_ppid:
trace("--ppid\n");
arg = grab_gnu_arg();