top: kill/nice provide for a default pid
As an aid to the above 2 commands, and as a prelude to an upcoming 'inspect other output' capability, the act of selecting a process for either has been simplified. Positioning a task as the first one displayed, via the up/down arrow keys, will now establish it as a default selection for the appropriate command. Thus, that pid will then be incorporated in a subsequent input prompt. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
4dfb01aa37
commit
39f4067c66
35
top/top.c
35
top/top.c
@ -1068,17 +1068,20 @@ static float get_float (const char *prompt) {
|
||||
} // end: get_float
|
||||
|
||||
|
||||
#define GET_INT_BAD INT_MIN
|
||||
#define GET_INTNONE (INT_MIN + 1)
|
||||
|
||||
/*
|
||||
* Get an integer from the user, returning INT_MIN for error */
|
||||
static int get_int (const char *prompt) {
|
||||
char *line;
|
||||
int n;
|
||||
|
||||
if (!(*(line = linein(prompt)))) return INT_MIN;
|
||||
if (!(*(line = linein(prompt)))) return GET_INTNONE;
|
||||
// note: we've got to allow negative ints (renice)
|
||||
if (strcspn(line, "-+0123456789")) {
|
||||
show_msg(N_txt(BAD_integers_txt));
|
||||
return INT_MIN;
|
||||
return GET_INT_BAD;
|
||||
}
|
||||
sscanf(line, "%d", &n);
|
||||
return n;
|
||||
@ -3132,10 +3135,10 @@ static void keys_global (int ch) {
|
||||
if (Secure_mode) {
|
||||
show_msg(N_txt(NOT_onsecure_txt));
|
||||
} else {
|
||||
int pid, sig = SIGTERM;
|
||||
char *str;
|
||||
if (-1 < (pid = get_int(N_txt(GET_pid2kill_txt)))) {
|
||||
str = linein(fmtmk(N_fmt(GET_sigs_num_fmt), pid, SIGTERM));
|
||||
int pid, sig = SIGTERM, def = w->ppt[w->begtask]->tid;
|
||||
if (GET_INT_BAD < (pid = get_int(fmtmk(N_txt(GET_pid2kill_fmt), def)))) {
|
||||
char *str = linein(fmtmk(N_fmt(GET_sigs_num_fmt), pid, SIGTERM));
|
||||
if (0 > pid) pid = def;
|
||||
if (*str) sig = signal_name_to_number(str);
|
||||
if (0 < sig && kill(pid, sig))
|
||||
show_msg(fmtmk(N_fmt(FAIL_signals_fmt)
|
||||
@ -3148,18 +3151,22 @@ static void keys_global (int ch) {
|
||||
if (Secure_mode)
|
||||
show_msg(N_txt(NOT_onsecure_txt));
|
||||
else {
|
||||
int val, pid;
|
||||
if (-1 < (pid = get_int(N_txt(GET_pid2nice_txt)))
|
||||
&& INT_MIN < (val = get_int(fmtmk(N_fmt(GET_nice_num_fmt), pid))))
|
||||
if (setpriority(PRIO_PROCESS, (unsigned)pid, val))
|
||||
show_msg(fmtmk(N_fmt(FAIL_re_nice_fmt)
|
||||
, pid, val, strerror(errno)));
|
||||
int val, pid, def = w->ppt[w->begtask]->tid;
|
||||
if (GET_INT_BAD < (pid = get_int(fmtmk(N_txt(GET_pid2nice_fmt), def)))) {
|
||||
if (0 > pid) pid = def;
|
||||
if (GET_INTNONE < (val = get_int(fmtmk(N_fmt(GET_nice_num_fmt), pid))))
|
||||
if (setpriority(PRIO_PROCESS, (unsigned)pid, val))
|
||||
show_msg(fmtmk(N_fmt(FAIL_re_nice_fmt)
|
||||
, pid, val, strerror(errno)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
{ int wide = get_int(fmtmk(N_fmt(XTRA_fixwide_fmt), Rc.fixed_widest));
|
||||
if (-1 < wide) Rc.fixed_widest = wide;
|
||||
else if (INT_MIN < wide) Rc.fixed_widest = -1;
|
||||
if (GET_INTNONE < wide) {
|
||||
if (-1 < wide) Rc.fixed_widest = wide;
|
||||
else if (INT_MIN < wide) Rc.fixed_widest = -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Z':
|
||||
|
@ -314,11 +314,11 @@ static void build_norm_nlstab (void) {
|
||||
Norm_nlstab[DELAY_change_fmt] = _("Change delay from %.1f to");
|
||||
Norm_nlstab[THREADS_show_fmt] = _("Show threads %s");
|
||||
Norm_nlstab[IRIX_curmode_fmt] = _("Irix mode %s");
|
||||
Norm_nlstab[GET_pid2kill_txt] = _("pid to signal/kill");
|
||||
Norm_nlstab[GET_pid2kill_fmt] = _("PID to signal/kill [default pid = %d]");
|
||||
Norm_nlstab[GET_sigs_num_fmt] = _("Send pid %d signal [%d/sigterm]");
|
||||
Norm_nlstab[FAIL_signals_fmt] = _("Failed signal pid '%d' with '%d': %s");
|
||||
Norm_nlstab[BAD_signalid_txt] = _("Invalid signal");
|
||||
Norm_nlstab[GET_pid2nice_txt] = _("PID to renice");
|
||||
Norm_nlstab[GET_pid2nice_fmt] = _("PID to renice [default pid = %d]");
|
||||
Norm_nlstab[GET_nice_num_fmt] = _("Renice PID %d to value");
|
||||
Norm_nlstab[FAIL_re_nice_fmt] = _("Failed renice of PID %d to %d: %s");
|
||||
Norm_nlstab[NAME_windows_fmt] = _("Rename window '%s' to (1-3 chars)");
|
||||
|
@ -72,7 +72,7 @@ enum norm_nls {
|
||||
FAIL_statget_txt, FAIL_statopn_fmt, FAIL_tty_get_txt, FAIL_tty_mod_fmt,
|
||||
FAIL_tty_raw_fmt, FAIL_widecpu_txt, FAIL_widepid_txt, FIND_no_find_fmt,
|
||||
FIND_no_next_txt, FOREST_modes_fmt, FOREST_views_txt, GET_find_str_txt,
|
||||
GET_max_task_fmt, GET_nice_num_fmt, GET_pid2kill_txt, GET_pid2nice_txt,
|
||||
GET_max_task_fmt, GET_nice_num_fmt, GET_pid2kill_fmt, GET_pid2nice_fmt,
|
||||
GET_sigs_num_fmt, GET_user_ids_txt, HELP_cmdline_fmt, HILIGHT_cant_txt,
|
||||
IRIX_curmode_fmt, LIMIT_exceed_fmt, MISSING_args_fmt, NAME_windows_fmt,
|
||||
NOT_onsecure_txt, NOT_smp_cpus_txt, OFF_one_word_txt, ON_word_only_txt,
|
||||
|
Loading…
Reference in New Issue
Block a user