This commit is contained in:
albert 2002-12-07 22:36:21 +00:00
parent 041bf4ebba
commit 967acac8b7
3 changed files with 84 additions and 75 deletions

22
top.1

@ -254,7 +254,7 @@ Starts \*(Me with the last remembered 'i' state reversed.
When this toggle is \*F, tasks that are idled or zombied will not be displayed. When this toggle is \*F, tasks that are idled or zombied will not be displayed.
.TP 5 .TP 5
\-\fBn\fR :\fB Number of iterations\fR limit as:\ \ \fB -n number\fR \-\fBn\fR :\fB Number of iterations\fR limit as:\fB\ \ -n number\fR
Specifies the maximum number of iterations, or frames, \*(Me should Specifies the maximum number of iterations, or frames, \*(Me should
produce before ending. produce before ending.
@ -303,7 +303,7 @@ For additional information on sort provisions \*(Xt 3c. TASK Area Commands.
.TP 3 .TP 3
a:\fB PID\fR \*(EM Process Id\fR a:\fB PID\fR \*(EM Process Id\fR
The task's unique process ID, which periodically wraps at 32767, The task's unique process ID, which periodically wraps,
though never restarting at zero. though never restarting at zero.
.TP 3 .TP 3
@ -311,22 +311,20 @@ b:\fB PPID\fR \*(EM Parent Process Pid\fR
The process ID of a task's parent. The process ID of a task's parent.
.TP 3 .TP 3
c:\fB PGID\fR \*(EM Process Group Id\fR c:\fB RUSER\fR \*(EM Real User Name\fR
The grouping of tasks which becomes part of job control. The real user name of the task's owner.
It is used for distribution of signals and to arbitrate terminal I/O requests.
There is one process group per pipeline.
.TP 3 .TP 3
d:\fB UID\fR \*(EM User Id\fR d:\fB UID\fR \*(EM User Id\fR
The user ID of the task's owner. The effective user ID of the task's owner.
.TP 3 .TP 3
e:\fB USER\fR \*(EM User Name e:\fB USER\fR \*(EM User Name\fR
The user name of the task's owner. The effective user name of the task's owner.
.TP 3 .TP 3
f:\fB GROUP\fR \*(EM Group Name f:\fB GROUP\fR \*(EM Group Name\fR
The group name of the task's owner. The effective group name of the task's owner.
.TP 3 .TP 3
g:\fB TTY\fR \*(EM Controlling Tty g:\fB TTY\fR \*(EM Controlling Tty
@ -1179,8 +1177,8 @@ This entirely new and enhanced replacement was written by:
.. ..
With invaluable help from: With invaluable help from:
Craig Small, <csmall@small.dropbear.id.au>
Albert D\. Cahalan, <albert@users.sf.net> Albert D\. Cahalan, <albert@users.sf.net>
Craig Small, <csmall@small.dropbear.id.au>
.ig .ig
.rj 2 .rj 2

105
top.c

@ -98,8 +98,7 @@ static int Screen_cols, Screen_rows, Max_lines;
static int Msg_row; static int Msg_row;
/* Global/Non-windows mode stuff that is NOT persistent */ /* Global/Non-windows mode stuff that is NOT persistent */
static int Crufty_rcf = 0, // if we read an old config, write one too static int No_ksyms = -1, // set to '0' if ksym avail, '1' otherwise
No_ksyms = -1, // set to '0' if ksym avail, '1' otherwise
PSDBopen = 0, // set to '1' if psdb opened (now postponed) PSDBopen = 0, // set to '1' if psdb opened (now postponed)
Batch = 0, // batch mode, collect no input, dumb output Batch = 0, // batch mode, collect no input, dumb output
Loops = -1, // number of iterations, -1 loops forever Loops = -1, // number of iterations, -1 loops forever
@ -144,8 +143,8 @@ static WIN_t Winstk [GROUPSMAX],
and/or that would be too cumbersome managed as parms, and/or that would be too cumbersome managed as parms,
and/or that are simply more efficiently handled as globals and/or that are simply more efficiently handled as globals
(first 2 persist beyond a single frame, changed infrequently) */ (first 2 persist beyond a single frame, changed infrequently) */
static int Frams_libflags; // current PROC_FIILxxx flags (0 = need new) static int Frames_libflags; // PROC_FILLxxx flags (0 = need new)
//atic int Frams_maxcmdln; // the largest from the 4 windows //atic int Frames_maxcmdln; // the largest from the 4 windows
static unsigned Frame_maxtask; // last known number of active tasks static unsigned Frame_maxtask; // last known number of active tasks
// ie. current 'size' of proc table // ie. current 'size' of proc table
static unsigned Frame_running, // state categories for this frame static unsigned Frame_running, // state categories for this frame
@ -947,7 +946,7 @@ static void prochlp (proc_t *this)
// this task wins it's displayable screen row lottery... */ // this task wins it's displayable screen row lottery... */
this->pcpu = tics; this->pcpu = tics;
strim(1, this->cmd); strim(1, this->cmd);
// if (Frams_maxcmdln) { } // if (Frames_maxcmdln) { }
// shout this to the world with the final call (or us the next time in) // shout this to the world with the final call (or us the next time in)
Frame_maxtask++; Frame_maxtask++;
} }
@ -1163,7 +1162,6 @@ static const FLD_t *ft_idx_to_ptr (const int i) {
if (i >= MAXTBL(Fieldstab)) return NULL; if (i >= MAXTBL(Fieldstab)) return NULL;
return Fieldstab + i; return Fieldstab + i;
} }
#endif
// convert, or -1 for failure // convert, or -1 for failure
@ -1174,6 +1172,7 @@ static int ft_ptr_to_idx (const FLD_t *p) {
if (i >= MAXTBL(Fieldstab)) return -1; if (i >= MAXTBL(Fieldstab)) return -1;
return i; return i;
} }
#endif
#if 0 #if 0
@ -1200,7 +1199,9 @@ static void rc_bugless (const RCF_t *const rc) {
* For each of the 4 windows: * For each of the 4 windows:
* line a: contains winname, fieldscur * line a: contains winname, fieldscur
* line b: contains winflags, sortindx, maxtasks * line b: contains winflags, sortindx, maxtasks
* line c: contains summclr, msgsclr, headclr, taskclr */ * line c: contains summclr, msgsclr, headclr, taskclr
* line d: if present, would crash procps-3.1.1
*/
static int rc_read_new (const char *const buf, RCF_t *rc) { static int rc_read_new (const char *const buf, RCF_t *rc) {
int i; int i;
int cnt; int cnt;
@ -1237,12 +1238,19 @@ static int rc_read_new (const char *const buf, RCF_t *rc) {
if (cnt != 4) return -(11+100*i); if (cnt != 4) return -(11+100*i);
cp = strchr(cp, '\n'); cp = strchr(cp, '\n');
if (!cp++) return -(12+100*i); if (!cp++) return -(12+100*i);
while (*cp == '\t') { // skip unknown per-window settings
cp = strchr(cp, '\n');
if (!cp++) return -(13+100*i);
}
} }
return 13; return 13;
} }
static int rc_read_old (const char *const buf, RCF_t *rc) { static int rc_read_old (const char *const buf, RCF_t *rc) {
const char std[] = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzJj......";
const char old[] = "AaBb..CcDd..GgHhIiYyEeWw..FfMmOoTtKkLlPpJjSsVvXxUuZz[{QqNnRr";
unsigned u; unsigned u;
const char *cp; const char *cp;
unsigned c_show = 0; unsigned c_show = 0;
@ -1254,6 +1262,7 @@ static int rc_read_old (const char *const buf, RCF_t *rc) {
cp = buf+2; // skip the "\n\n" we stuck at the beginning cp = buf+2; // skip the "\n\n" we stuck at the beginning
u = 0; u = 0;
for (;;) { for (;;) {
const char *tmp;
if (u+1 >= sizeof rc->win[0].fieldscur) return -1; if (u+1 >= sizeof rc->win[0].fieldscur) return -1;
int c = *cp++; int c = *cp++;
if (c == '\0') return -2; if (c == '\0') return -2;
@ -1262,15 +1271,9 @@ static int rc_read_old (const char *const buf, RCF_t *rc) {
if (~c & 0x20) c_show |= 1 << (c & 0x1f); // 0x20 means lowercase means hidden if (~c & 0x20) c_show |= 1 << (c & 0x1f); // 0x20 means lowercase means hidden
if (scoreboard[c|0xe0u]) badchar++; // duplicates not allowed if (scoreboard[c|0xe0u]) badchar++; // duplicates not allowed
scoreboard[c|0xe0u]++; scoreboard[c|0xe0u]++;
if (c == '|') continue; // Rik's top ships with a garbage character tmp = strchr(old,c);
if (c == '[') c = 'Y'; // Rik's top ships with 3x of "#C" if (tmp) c = *((tmp-old)+std);
if (c == '{') c = 'y'; // another one... and '}' to please Jim's editor else c = '.';
if (c == 'N') c = 'n'; // usage differs, so turn this off
if (c == 'Q') c = 'q'; // usage differs, so turn this off
if (c == 'R') c = 'r'; // usage differs, so turn this off
c = ft_cvt_char(FT_OLD_fmt, FT_NEW_fmt, c);
if (!c) return -4; // error value
if (c == '.') return -5; // error value
if (scoreboard[c&0x1fu]) badchar++; // duplicates not allowed if (scoreboard[c&0x1fu]) badchar++; // duplicates not allowed
scoreboard[c&0x1fu]++; scoreboard[c&0x1fu]++;
rc->win[0].fieldscur[u++] = c; rc->win[0].fieldscur[u++] = c;
@ -1278,8 +1281,8 @@ static int rc_read_old (const char *const buf, RCF_t *rc) {
rc->win[0].fieldscur[u++] = '\0'; rc->win[0].fieldscur[u++] = '\0';
if (u < 21) return -6; // catch junk, not good files (had 23 chars in one) if (u < 21) return -6; // catch junk, not good files (had 23 chars in one)
if (u > 33) return -7; // catch junk, not good files (had 29 chars in one) if (u > 33) return -7; // catch junk, not good files (had 29 chars in one)
// fprintf(stderr,"badchar: %d\n",badchar); sleep(2); // fprintf(stderr, "badchar: %d\n", badchar); sleep(2);
if (badchar > 3) return -8; // too much junk if (badchar > 8) return -8; // too much junk
if (!c_show) return -9; // nothing was shown if (!c_show) return -9; // nothing was shown
// rest of file is optional, but better look right if it exists // rest of file is optional, but better look right if it exists
@ -1334,9 +1337,9 @@ static int rc_read_old (const char *const buf, RCF_t *rc) {
c = 0; // for scoreboard c = 0; // for scoreboard
rc->win[0].sortindx = P_CPU; rc->win[0].sortindx = P_CPU;
break; break;
case 'A': case 'A': // supposed to be start_time
c = 0; // for scoreboard c = 0; // for scoreboard
rc->win[0].sortindx = P_PID; // was by start_time (non-display) rc->win[0].sortindx = P_PID;
break; break;
case 'T': case 'T':
c = 0; // for scoreboard c = 0; // for scoreboard
@ -1393,7 +1396,7 @@ static void rc_write_new (FILE *fp) {
} }
} }
#if 0
static void rc_write_old (FILE *fp) { static void rc_write_old (FILE *fp) {
char buf[SMLBUFSIZ]; char buf[SMLBUFSIZ];
char *cp = Curwin->rc.fieldscur; char *cp = Curwin->rc.fieldscur;
@ -1462,13 +1465,13 @@ static void rc_write_old (FILE *fp) {
*cp++ = '\0'; *cp++ = '\0';
fprintf(fp, "%s\n\n\n", buf); // important "\n\n" separator! fprintf(fp, "%s\n\n\n", buf); // important "\n\n" separator!
} }
#endif
static const char *rc_write_whatever (void) { static const char *rc_write_whatever (void) {
FILE *fp = fopen(Rc_name, "w"); FILE *fp = fopen(Rc_name, "w");
if (!fp) return strerror(errno); if (!fp) return strerror(errno);
if (Crufty_rcf) rc_write_old(fp); // if (Crufty_rcf) rc_write_old(fp);
rc_write_new(fp); rc_write_new(fp);
fclose(fp); fclose(fp);
return NULL; return NULL;
@ -1612,9 +1615,12 @@ static void configs_read (void)
fbuf[0] = '\n'; fbuf[0] = '\n';
fbuf[1] = '\n'; fbuf[1] = '\n';
fbuf[num+2] = '\0'; fbuf[num+2] = '\0';
if (rc_read_old(fbuf, &rcf) > 0) Crufty_rcf = 1; //fprintf(stderr,"rc_read_old returns %d\n",rc_read_old(fbuf, &rcf));
else rcf = def_rcf; // on failure, maybe mangled //sleep(2);
rc_read_new(fbuf, &rcf); if (rc_read_new(fbuf, &rcf) < 0) {
rcf = def_rcf; // on failure, maybe mangled
if (rc_read_old(fbuf, &rcf) < 0) rcf = def_rcf;
}
delay = rcf.delay_time; delay = rcf.delay_time;
} }
close(fd); close(fd);
@ -1719,6 +1725,12 @@ static void parse_args (char **args)
case 'S': case 'S':
TOGw(Curwin, Show_CTIMES); TOGw(Curwin, Show_CTIMES);
break; break;
// case 'u':
// if (cp[1]) cp++;
// else if (*args) cp = *args++;
// else std_err("-u missing name");
// cp += snprintf(Curwin->colusrnam, USRNAMSIZ-1, "%s", cp);
// break;
default : default :
std_err(fmtmk("unknown argument '%c'\nusage:\t%s%s" std_err(fmtmk("unknown argument '%c'\nusage:\t%s%s"
, *cp, Myname, usage)); , *cp, Myname, usage));
@ -1800,9 +1812,9 @@ static void display_fields (const char *fields, const char *xtra)
for (i = 0; fields[i]; ++i) { for (i = 0; fields[i]; ++i) {
const FLD_t *f = ft_get_ptr(FT_NEW_fmt, fields[i]); const FLD_t *f = ft_get_ptr(FT_NEW_fmt, fields[i]);
int b = isupper(fields[i]); int b = isupper(fields[i]);
if (!f) continue; // hey, should be std_err! if (!f) continue; // hey, should be std_err!
/* advance past any leading spaces */ for (p = f->head; ' ' == *p; ++p) // advance past any leading spaces
for (p = f->head; ' ' == *p; ++p)
; ;
PUTT("%s%s%c %c: %-10s = %s" PUTT("%s%s%c %c: %-10s = %s"
, tg2((i / rmax) * cmax, (i % rmax) + yRSVD) , tg2((i / rmax) * cmax, (i % rmax) + yRSVD)
@ -1935,8 +1947,8 @@ static void reframewins (void)
const char *h; const char *h;
int i, needpsdb = 0; int i, needpsdb = 0;
// Frams_libflags = 0; // should be called only when it's zero // Frames_libflags = 0; // should be called only when it's zero
// Frams_maxcmdln = 0; // becomes largest from up to 4 windows, if visible // Frames_maxcmdln = 0; // to become largest from up to 4 windows, if visible
w = Curwin; w = Curwin;
do { do {
if (!Rc.mode_altscr || CHKw(w, VISIBLE_tsk)) { if (!Rc.mode_altscr || CHKw(w, VISIBLE_tsk)) {
@ -1976,12 +1988,12 @@ static void reframewins (void)
if (P_CMD == w->procflags[i]) { if (P_CMD == w->procflags[i]) {
s = scat(s, fmtmk(Fieldstab[P_CMD].fmts, w->maxcmdln, w->maxcmdln, h)); s = scat(s, fmtmk(Fieldstab[P_CMD].fmts, w->maxcmdln, w->maxcmdln, h));
if (CHKw(w, Show_CMDLIN)) { if (CHKw(w, Show_CMDLIN)) {
Frams_libflags |= L_CMDLINE; Frames_libflags |= L_CMDLINE;
// if (w->maxcmdln > Frams_maxcmdln) Frams_maxcmdln = w->maxcmdln; // if (w->maxcmdln > Frames_maxcmdln) Frames_maxcmdln = w->maxcmdln;
} }
} else } else
s = scat(s, h); s = scat(s, h);
Frams_libflags |= Fieldstab[w->procflags[i]].lflg; Frames_libflags |= Fieldstab[w->procflags[i]].lflg;
} }
} }
if (Rc.mode_altscr) w = w->next; if (Rc.mode_altscr) w = w->next;
@ -1997,11 +2009,11 @@ static void reframewins (void)
PSDBopen = 1; PSDBopen = 1;
} }
} }
if (Frams_libflags & L_EITHER) { if (Frames_libflags & L_EITHER) {
Frams_libflags &= ~L_EITHER; Frames_libflags &= ~L_EITHER;
if (!(Frams_libflags & L_stat)) Frams_libflags |= L_status; if (!(Frames_libflags & L_stat)) Frames_libflags |= L_status;
} }
if (!Frams_libflags) Frams_libflags = L_DEFAULT; if (!Frames_libflags) Frames_libflags = L_DEFAULT;
} }
@ -2214,7 +2226,7 @@ static void wins_resize (int dont_care_sig)
Pseudo_scrn = alloc_r(Pseudo_scrn, Pseudo_size); Pseudo_scrn = alloc_r(Pseudo_scrn, Pseudo_size);
// force rebuild of column headers AND libproc/readproc requirements // force rebuild of column headers AND libproc/readproc requirements
Frams_libflags = 0; Frames_libflags = 0;
} }
@ -2598,7 +2610,7 @@ static void do_key (unsigned c)
( At this point we have a human being involved and so have all the time ) ( At this point we have a human being involved and so have all the time )
( in the world. We can afford a few extra cpu cycles every now & then! ) ( in the world. We can afford a few extra cpu cycles every now & then! )
*/ */
Frams_libflags = 0; Frames_libflags = 0;
} }
@ -2668,7 +2680,7 @@ static proc_t **summary_show (void)
sleep(1); sleep(1);
} else } else
putp(Batch ? "\n\n" : Cap_home); putp(Batch ? "\n\n" : Cap_home);
p_table = procs_refresh(p_table, Frams_libflags); p_table = procs_refresh(p_table, Frames_libflags);
/* /*
** Display Uptime and Loadavg */ ** Display Uptime and Loadavg */
@ -2936,10 +2948,8 @@ static void window_show (proc_t **ppt, WIN_t *q, int *lscr)
while ( -1 != ppt[i]->pid && *lscr < Max_lines while ( -1 != ppt[i]->pid && *lscr < Max_lines
&& (!q->winlines || (lwin <= q->winlines)) ) { && (!q->winlines || (lwin <= q->winlines)) ) {
if ((CHKw(q, Show_IDLEPS) if ((CHKw(q, Show_IDLEPS) || ('S' != ppt[i]->state && 'Z' != ppt[i]->state))
|| ('S' != ppt[i]->state && 'Z' != ppt[i]->state)) && ((!q->colusrnam[0]) || (!strcmp(q->colusrnam, ppt[i]->euser)))) {
&& ((!q->colusrnam[0])
|| (!strcmp(q->colusrnam, ppt[i]->euser)) ) ) {
/* /*
** Display a process Row */ ** Display a process Row */
task_show(q, ppt[i]); task_show(q, ppt[i]);
@ -3020,7 +3030,7 @@ static void frame_make (void)
/* note: except for PROC_PID, all libproc flags are managed by /* note: except for PROC_PID, all libproc flags are managed by
reframewins(), who also builds each window's column headers */ reframewins(), who also builds each window's column headers */
if (!Frams_libflags) { if (!Frames_libflags) {
reframewins(); reframewins();
memset(Pseudo_scrn, '\0', Pseudo_size); memset(Pseudo_scrn, '\0', Pseudo_size);
} }
@ -3051,8 +3061,9 @@ static void frame_make (void)
/* clear to end-of-screen (critical if last window is 'idleps off'), /* clear to end-of-screen (critical if last window is 'idleps off'),
then put the cursor in-its-place, and rid us of any prior frame's msg then put the cursor in-its-place, and rid us of any prior frame's msg
(main loop must iterate such that we're always called before sleep) */ (main loop must iterate such that we're always called before sleep) */
PUTT("%s%s%s" PUTT("%s%s%s%s"
, (scrlins < Max_lines) ? Cap_clr_eos : "" , scrlins < Max_lines ? "\n" : ""
, scrlins < Max_lines ? Cap_clr_eos : ""
, tg2(0, Msg_row) , tg2(0, Msg_row)
, Cap_clr_eol); , Cap_clr_eol);
fflush(stdout); fflush(stdout);

2
top.h

@ -324,7 +324,7 @@ typedef struct WIN_t {
/* The default fields displayed and their order, /* The default fields displayed and their order,
if nothing is specified by the loser, oops user */ if nothing is specified by the loser, oops user */
#define DEF_FIELDS "AEHIOQTWKNMXbcdfgjplrsuvyz" #define DEF_FIELDS "AEHIOQTWKNMbcdfgjplrsuvyzX"
/* Pre-configured field groupss */ /* Pre-configured field groupss */
#define JOB_FIELDS "ABXcefgjlrstuvyzMKNHIWOPQD" #define JOB_FIELDS "ABXcefgjlrstuvyzMKNHIWOPQD"
#define MEM_FIELDS "ANOPQRSTUVXbcdefgjlmyzWHIK" #define MEM_FIELDS "ANOPQRSTUVXbcdefgjlmyzWHIK"