top: provide command line sort field override switches
This commit adds two new command line switches dealing with the potential need to automate/script the setting of top's current sort field independent of the rcfile. The -o (lower case) switch requires a lone valid field name as an argument, from among the 42 currently used. Then, it overrides the config file's Curwin->sortindx. And since field names are now translatable, they could diverge from those reflected in the documentation. So, a 2nd switch of -O (upper case) is also provided which outputs all names as translated and understood by top. (now that we know a '.' + 2 spaces is squeezed to one) (everything's perfectly justified, but it's just luck) Reference(s): Bug-Redhat: https://bugzilla.redhat.com/871844 http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857,9 http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857,15 http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857,16 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
d747659ad8
commit
407d1fc8f2
20
top/top.1
20
top/top.1
@ -53,8 +53,9 @@
|
||||
.ds CG \'current\' window/field group
|
||||
.ds CI interactive command
|
||||
\# - Note: our 'Command Line' used in 2 places
|
||||
.ds CL \-\fBhv\fR|\-\fBbcHiSs\fR \-\fBd\fR delay \-\fBn\fR limit \
|
||||
\-\fBu\fR|\fBU\fR user \-\fBp\fR pid[,pid] \-\fBw\fR [cols] \fR
|
||||
\# ( and managed to fit in an 80x24 terminal )
|
||||
.ds CL \-\fBhv\fR|\-\fBbcHiOSs\fR \-\fBd\fR secs \-\fBn\fR max \
|
||||
\-\fBu\fR|\fBU\fR user \-\fBp\fR pid \-\fBo\fR fld \-\fBw\fR [cols] \fR
|
||||
.ds CO command\-line option
|
||||
.ds CT command toggle
|
||||
.ds CW \'current\' window
|
||||
@ -301,6 +302,21 @@ For additional information regarding this toggle
|
||||
Specifies the maximum number of iterations, or frames, \*(We should
|
||||
produce before ending.
|
||||
|
||||
.TP 5
|
||||
\-\fBo\fR :\fI Override-sort-field\fR as:\fB\ \ \-o fieldname \fR
|
||||
Specifies the name of the field on which tasks will be sorted, independent
|
||||
of what is reflected in the configuration file.
|
||||
|
||||
This option exists primarily to support automated/scripted batch mode
|
||||
operation.
|
||||
|
||||
.TP 5
|
||||
\-\fBO\fR :\fI Output-field-names \fR
|
||||
This option acts as a form of help for the above \-o option.
|
||||
It will cause \*(We to print each of the available field names on a
|
||||
separate line, then quit.
|
||||
Such names are subject to nls translation.
|
||||
|
||||
.TP 5
|
||||
\-\fBp\fR :\fI Monitor-PIDs\fR mode as:\fB\ \ \-pN1 -pN2 ...\fR\ \ or\fB\ \ \-pN1,N2,N3 ... \fR
|
||||
Monitor only processes with specified process IDs.
|
||||
|
23
top/top.c
23
top/top.c
@ -3177,6 +3177,7 @@ static void parse_args (char **args) {
|
||||
static const char numbs_str[] = "+,-.0123456789";
|
||||
float tmp_delay = MAXFLOAT;
|
||||
char *p;
|
||||
int i;
|
||||
|
||||
while (*args) {
|
||||
const char *cp = *(args++);
|
||||
@ -3212,8 +3213,8 @@ static void parse_args (char **args) {
|
||||
break;
|
||||
case 'h':
|
||||
case 'v':
|
||||
fprintf(stdout, N_fmt(HELP_cmdline_fmt)
|
||||
, procps_version, Myname, N_txt(USAGE_abbrev_txt));
|
||||
puts(fmtmk(N_fmt(HELP_cmdline_fmt)
|
||||
, procps_version, Myname, N_txt(USAGE_abbrev_txt)));
|
||||
bye_bye(NULL);
|
||||
case 'i':
|
||||
TOGw(Curwin, Show_IDLEPS);
|
||||
@ -3226,9 +3227,25 @@ static void parse_args (char **args) {
|
||||
if (1 != sscanf(cp, "%d", &Loops) || 1 > Loops)
|
||||
error_exit(fmtmk(N_fmt(BAD_niterate_fmt), cp));
|
||||
break;
|
||||
case 'o':
|
||||
if (cp[1]) cp++;
|
||||
else if (*args) cp = *args++;
|
||||
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
|
||||
for (i = 0; i < P_MAXPFLGS; i++)
|
||||
if (!STRCMP(cp, N_col(i))) break;
|
||||
if (i == P_MAXPFLGS)
|
||||
error_exit(fmtmk(N_fmt(XTRA_sortopt_fmt), cp));
|
||||
OFFw(Curwin, Show_FOREST);
|
||||
Curwin->rc.sortindx = i;
|
||||
cp += strlen(cp);
|
||||
break;
|
||||
case 'O':
|
||||
for (i = 0; i < P_MAXPFLGS; i++)
|
||||
puts(N_col(i));
|
||||
bye_bye(NULL);
|
||||
case 'p':
|
||||
if (Curwin->usrseltyp) error_exit(N_txt(SELECT_clash_txt));
|
||||
do { int i, pid;
|
||||
do { int pid;
|
||||
if (cp[1]) cp++;
|
||||
else if (*args) cp = *args++;
|
||||
else error_exit(fmtmk(N_fmt(MISSING_args_fmt), ch));
|
||||
|
@ -278,10 +278,10 @@ static void build_norm_nlstab (void) {
|
||||
"\tsee http://www.debian.org/Bugs/Reporting\n");
|
||||
Norm_nlstab[WRONG_switch_fmt] = _(""
|
||||
"inappropriate '%s'\n"
|
||||
"usage:\t%s%s");
|
||||
"Usage:\n %s%s");
|
||||
Norm_nlstab[HELP_cmdline_fmt] = _(""
|
||||
"\t%s\n"
|
||||
"usage:\t%s%s");
|
||||
" %s\n"
|
||||
"Usage:\n %s%s");
|
||||
Norm_nlstab[FAIL_statopn_fmt] = _("failed /proc/stat open: %s");
|
||||
Norm_nlstab[FAIL_openlib_fmt] = _("failed openproc: %s");
|
||||
Norm_nlstab[BAD_delayint_fmt] = _("bad delay interval '%s'");
|
||||
@ -292,14 +292,14 @@ static void build_norm_nlstab (void) {
|
||||
Norm_nlstab[BAD_widtharg_fmt] = _("bad width arg '%s', must > %d");
|
||||
Norm_nlstab[UNKNOWN_opts_fmt] = _(""
|
||||
"unknown option '%c'\n"
|
||||
"usage:\t%s%s");
|
||||
"Usage:\n %s%s");
|
||||
Norm_nlstab[DELAY_secure_txt] = _("-d disallowed in \"secure\" mode");
|
||||
Norm_nlstab[DELAY_badarg_txt] = _("-d requires positive argument");
|
||||
Norm_nlstab[ON_word_only_txt] = _("On");
|
||||
Norm_nlstab[OFF_one_word_txt] = _("Off");
|
||||
/* Translation Hint: Only the following words should be translated
|
||||
. delay, limit, user, cols (abbreviation for columns)*/
|
||||
Norm_nlstab[USAGE_abbrev_txt] = _(" -hv | -bcHiSs -d delay -n limit -u|U user -p pid[,pid] -w [cols]");
|
||||
Norm_nlstab[USAGE_abbrev_txt] = _(" -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]");
|
||||
Norm_nlstab[FAIL_statget_txt] = _("failed /proc/stat read");
|
||||
Norm_nlstab[FOREST_modes_fmt] = _("Forest mode %s");
|
||||
Norm_nlstab[FAIL_tty_get_txt] = _("failed tty get");
|
||||
@ -369,6 +369,7 @@ static void build_norm_nlstab (void) {
|
||||
Norm_nlstab[FIND_no_find_fmt] = _("%s\"%s\" not found");
|
||||
Norm_nlstab[XTRA_fixwide_fmt] = _("width incr is %d, change to (0 default, -1 auto)");
|
||||
Norm_nlstab[XTRA_warncfg_txt] = _("Overwrite existing obsolete/corrupted rcfile?");
|
||||
Norm_nlstab[XTRA_sortopt_fmt] = _("unrecognized field name '%s'");
|
||||
#ifndef INSP_OFFDEMO
|
||||
Norm_nlstab[YINSP_demo01_txt] = _("Open Files");
|
||||
Norm_nlstab[YINSP_demo02_txt] = _("NUMA Info");
|
||||
|
@ -80,10 +80,7 @@ enum norm_nls {
|
||||
THREADS_show_fmt, TIME_accumed_fmt, UNKNOWN_cmds_txt, UNKNOWN_opts_fmt,
|
||||
USAGE_abbrev_txt, WORD_allcpus_txt, WORD_another_txt, WORD_eachcpu_fmt,
|
||||
WORD_process_txt, WORD_threads_txt, WRITE_rcfile_fmt, WRONG_switch_fmt,
|
||||
XTRA_fixwide_fmt,
|
||||
#ifndef WARN_CFG_OFF
|
||||
XTRA_warncfg_txt,
|
||||
#endif
|
||||
XTRA_fixwide_fmt, XTRA_sortopt_fmt, XTRA_warncfg_txt,
|
||||
#ifndef INSP_OFFDEMO
|
||||
YINSP_demo01_txt, YINSP_demo02_txt, YINSP_demo03_txt, YINSP_deqfmt_txt,
|
||||
YINSP_deqtyp_txt, YINSP_dstory_txt,
|
||||
|
Loading…
Reference in New Issue
Block a user