version 1.27, 2007/02/23 13:31:45 |
version 1.28, 2007/05/29 00:56:56 |
|
|
static int err_compar(const void *, const void *); |
static int err_compar(const void *, const void *); |
|
|
/* |
/* |
* show_help() - display the help screen; invoked in response to |
|
* either 'h' or '?'. |
|
*/ |
|
void |
|
show_help(void) |
|
{ |
|
printf("Top version %s, %s\n", version_string(), copyright); |
|
puts("These single-character commands are available:\n" |
|
"\n" |
|
"h | ? - help; show this text\n" |
|
"^L - redraw screen\n" |
|
"q - quit"); |
|
|
|
/* not all commands are available with overstrike terminals */ |
|
if (overstrike) { |
|
puts("\n" |
|
"Other commands are also available, but this terminal is not\n" |
|
"sophisticated enough to handle those commands gracefully.\n"); |
|
} else { |
|
puts( |
|
"+ - reset any g, p, or u filters\n" |
|
"C - toggle the display of command line arguments\n" |
|
"d count - show `count' displays, then exit\n" |
|
"e - list errors generated by last \"kill\" or \"renice\" command\n" |
|
"g string - filter on command name (g+ selects all commands)\n" |
|
"I | i - toggle the display of idle processes\n" |
|
"k [-sig] pid - send signal `-sig' to process `pid'\n" |
|
"n|# count - show `count' processes\n" |
|
"o field - specify sort order (size, res, cpu, time, pri)\n" |
|
"p pid - display process by `pid' (p+ selects all processes)\n" |
|
"r count pid - renice process `pid' to nice value `count'\n" |
|
"S - toggle the display of system processes\n" |
|
"s time - change delay between displays to `time' seconds\n" |
|
"T - toggle the display of threads\n" |
|
"u user - display processes for `user' (u+ selects all users)\n" |
|
"\n"); |
|
} |
|
} |
|
|
|
/* |
|
* Utility routines that help with some of the commands. |
* Utility routines that help with some of the commands. |
*/ |
*/ |
static char * |
static char * |
|
|
|
|
#define ERRMAX 20 |
#define ERRMAX 20 |
|
|
struct errs { /* structure for a system-call error */ |
struct errs errs[ERRMAX]; |
int err; /* value of errno (that is, the actual error) */ |
int errcnt; |
char *arg; /* argument that caused the error */ |
|
}; |
|
|
|
static struct errs errs[ERRMAX]; |
|
static int errcnt; |
|
static char *err_toomany = " too many errors occurred"; |
static char *err_toomany = " too many errors occurred"; |
static char *err_listem = |
static char *err_listem = |
" Many errors occurred. Press `e' to display the list of errors."; |
" Many errors occurred. Press `e' to display the list of errors."; |
|
|
static int |
static int |
err_compar(const void *e1, const void *e2) |
err_compar(const void *e1, const void *e2) |
{ |
{ |
const struct errs *p1 = (struct errs *) e1; |
const struct errs *p1 = (const struct errs *) e1; |
const struct errs *p2 = (struct errs *) e2; |
const struct errs *p2 = (const struct errs *) e2; |
int result; |
int result; |
|
|
if ((result = p1->err - p2->err) == 0) |
if ((result = p1->err - p2->err) == 0) |
|
|
error_count(void) |
error_count(void) |
{ |
{ |
return (errcnt); |
return (errcnt); |
} |
|
|
|
/* |
|
* show_errors() - display on stdout the current log of errors. |
|
*/ |
|
void |
|
show_errors(void) |
|
{ |
|
struct errs *errp = errs; |
|
int cnt = 0; |
|
|
|
printf("%d error%s:\n\n", errcnt, errcnt == 1 ? "" : "s"); |
|
while (cnt++ < errcnt) { |
|
printf("%5s: %s\n", errp->arg, |
|
errp->err == 0 ? "Not a number" : strerror(errp->err)); |
|
errp++; |
|
} |
|
} |
} |
|
|
/* |
/* |