top: do not refresh like crazy

This commit is contained in:
albert 2003-03-17 23:42:00 +00:00
parent 7775a65c4d
commit 1351592110
10 changed files with 49 additions and 25 deletions

4
NEWS
View File

@ -2,6 +2,10 @@ procps-3.1.6 --> procps-3.1.7
watch: --help now explains -t, --no-title #182246 watch: --help now explains -t, --no-title #182246
ps: warning directs users to the FAQ ps: warning directs users to the FAQ
top: batch mode can refresh by fractional seconds
top: faster start-up
top: do not refresh like crazy
ps: better crash message
procps-3.1.5 --> procps-3.1.6 procps-3.1.5 --> procps-3.1.6

5
README
View File

@ -1,7 +1,8 @@
COMPATIBILITY COMPATIBILITY
This code is intended for use with Linux 2.0.xx and above. This code is intended for use with Linux 2.2.xx, 2.4.xx,
Both libc 5 and libc 6 should work. 2.5.xx, and hopefully all future kernels. You should be
running a system with libc 6, but libc 5 might work too.
INSTALLATION INSTALLATION

View File

@ -266,7 +266,7 @@ hell:
*bufp = NULL; *bufp = NULL;
*roomp = 0; /* this function will never work again */ *roomp = 0; /* this function will never work again */
total = 0; total = 0;
close(fd); if(fd>0) close(fd);
return; return;
} }

View File

@ -9,7 +9,7 @@ global:
display_version; procps_version; linux_version_code; display_version; procps_version; linux_version_code;
Hertz; smp_num_cpus; Hertz; smp_num_cpus;
sprint_uptime; uptime; user_from_uid; print_uptime; loadavg; sprint_uptime; uptime; user_from_uid; print_uptime; loadavg;
pretty_print_signals; print_given_signals; unix_print_signals; signal_name_to_number; pretty_print_signals; print_given_signals; unix_print_signals; signal_name_to_number; signal_number_to_name;
meminfo; vminfo; meminfo; vminfo;
kb_active; kb_inactive; kb_main_buffers; kb_main_cached; kb_active; kb_inactive; kb_main_buffers; kb_main_cached;
kb_main_free; kb_main_total; kb_main_used; kb_swap_free; kb_main_free; kb_main_total; kb_main_used; kb_swap_free;

View File

@ -146,7 +146,7 @@ int signal_name_to_number(const char *restrict name){
return val+offset; return val+offset;
} }
static const char *signal_number_to_name(int signo){ const char *signal_number_to_name(int signo){
static char buf[32]; static char buf[32];
int n = number_of_signals; int n = number_of_signals;
signo &= 0x7f; /* need to process exit values too */ signo &= 0x7f; /* need to process exit values too */

View File

@ -18,6 +18,8 @@ EXTERN_C_BEGIN
/* return -1 on failure */ /* return -1 on failure */
extern int signal_name_to_number(const char *restrict name); extern int signal_name_to_number(const char *restrict name);
extern const char *signal_number_to_name(int signo);
extern int print_given_signals(int argc, const char *restrict const *restrict argv, int max_line); extern int print_given_signals(int argc, const char *restrict const *restrict argv, int max_line);
extern void pretty_print_signals(void); extern void pretty_print_signals(void);

View File

@ -40,9 +40,10 @@ static void signal_handler(int signo){
/* fprintf() is not reentrant, but we _exit() anyway */ /* fprintf() is not reentrant, but we _exit() anyway */
fprintf(stderr, fprintf(stderr,
"\n\n" "\n\n"
"Signal %d caught by ps (%s).\n" "Signal %d (%s) caught by ps (%s).\n"
"Please send bug reports to <acahalan@cs.uml.edu>\n", "Please send bug reports to <feedback@lists.sf.net> or <albert@users.sf.net>\n",
signo, signo,
signal_number_to_name(signo),
procps_version procps_version
); );
_exit(signo+128); _exit(signo+128);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 1998-2002 by Albert Cahalan; all rights reserved. * Copyright 1998-2003 by Albert Cahalan; all rights reserved.
* This file may be used subject to the terms and conditions of the * This file may be used subject to the terms and conditions of the
* GNU Library General Public License Version 2, or any later version * GNU Library General Public License Version 2, or any later version
* at your option, as published by the Free Software Foundation. * at your option, as published by the Free Software Foundation.

48
top.c
View File

@ -87,6 +87,10 @@ static int Monpidsidx = 0;
static char Msg_delayed [SMLBUFSIZ]; static char Msg_delayed [SMLBUFSIZ];
static int Msg_awaiting = 0; static int Msg_awaiting = 0;
// This is the select() timeout. Clear it in sig handlers to avoid a race.
static volatile struct timeval tv;
#define ZAP_TIMEOUT do{tv.tv_usec=0; tv.tv_sec=0;}while(0);
/* Configurable Display support ##################################*/ /* Configurable Display support ##################################*/
/* Current screen dimensions. /* Current screen dimensions.
@ -437,6 +441,7 @@ static void suspend (int dont_care_sig)
fflush(stdout); fflush(stdout);
raise(SIGSTOP); raise(SIGSTOP);
/* later, after SIGCONT... */ /* later, after SIGCONT... */
ZAP_TIMEOUT
if (!Batch) if (!Batch)
tcsetattr(STDIN_FILENO, TCSAFLUSH, &Rawtty); tcsetattr(STDIN_FILENO, TCSAFLUSH, &Rawtty);
} }
@ -2310,6 +2315,7 @@ static void wins_resize (int dont_care_sig)
// force rebuild of column headers AND libproc/readproc requirements // force rebuild of column headers AND libproc/readproc requirements
Frames_libflags = 0; Frames_libflags = 0;
ZAP_TIMEOUT
} }
@ -2804,7 +2810,12 @@ static proc_t **summary_show (void)
if (!p_table) { if (!p_table) {
p_table = procs_refresh(NULL, Frames_libflags); p_table = procs_refresh(NULL, Frames_libflags);
putp(Cap_clr_scr); putp(Cap_clr_scr);
sleep(1); #ifndef PROF
// sleep for half a second
tv.tv_sec = 0;
tv.tv_usec = 500000;
select(0, NULL, NULL, NULL, &tv); // ought to loop until done
#endif
} else } else
putp(Batch ? "\n\n" : Cap_home); putp(Batch ? "\n\n" : Cap_home);
p_table = procs_refresh(p_table, Frames_libflags); p_table = procs_refresh(p_table, Frames_libflags);
@ -2812,13 +2823,14 @@ static proc_t **summary_show (void)
/* /*
** Display Uptime and Loadavg */ ** Display Uptime and Loadavg */
if (CHKw(Curwin, View_LOADAV)) { if (CHKw(Curwin, View_LOADAV)) {
if (!Rc.mode_altscr) if (!Rc.mode_altscr) {
show_special(0, fmtmk(LOADAV_line, Myname, sprint_uptime())); show_special(0, fmtmk(LOADAV_line, Myname, sprint_uptime()));
else } else {
show_special(0, fmtmk(CHKw(Curwin, VISIBLE_tsk) show_special(0, fmtmk(CHKw(Curwin, VISIBLE_tsk)
? LOADAV_line_alt ? LOADAV_line_alt
: LOADAV_line : LOADAV_line
, Curwin->grpname, sprint_uptime())); , Curwin->grpname, sprint_uptime()));
}
Msg_row += 1; Msg_row += 1;
} }
@ -3228,26 +3240,30 @@ int main (int dont_care_argc, char **argv)
signal(SIGWINCH, wins_resize); signal(SIGWINCH, wins_resize);
for (;;) { for (;;) {
struct timeval tv; frame_make();
fd_set fs;
char c;
// This is it?
frame_make(); // Impossible!
if (Msg_awaiting) show_msg(Msg_delayed); if (Msg_awaiting) show_msg(Msg_delayed);
if (0 < Loops) --Loops; if (0 < Loops) --Loops;
if (!Loops) end_pgm(0); if (!Loops) end_pgm(0);
if (Batch) tv.tv_sec = Rc.delay_time;
sleep((unsigned)Rc.delay_time); tv.tv_usec = (Rc.delay_time - (int)Rc.delay_time) * 1000000;
else { // Linux reports time not slept,
tv.tv_sec = Rc.delay_time; // so we must reinit every time. if (Batch) {
tv.tv_usec = (Rc.delay_time - (int)Rc.delay_time) * 1000000; select(0, NULL, NULL, NULL, &tv); // ought to loop until done
} else {
long file_flags;
char c;
fd_set fs;
FD_ZERO(&fs); FD_ZERO(&fs);
FD_SET(STDIN_FILENO, &fs); FD_SET(STDIN_FILENO, &fs);
if (0 < select(STDIN_FILENO+1, &fs, NULL, NULL, &tv) file_flags = fcntl(STDIN_FILENO, F_GETFL);
&& 0 < chin(0, &c, 1)) if(file_flags==-1) file_flags=0;
do_key((unsigned)c); fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK|file_flags);
// check 1st, in case tv zeroed (by sig handler) before it got set
if (chin(0, &c, 1) <= 0) select(1, &fs, NULL, NULL, &tv);
if (chin(0, &c, 1) > 0) do_key((unsigned)c);
fcntl(STDIN_FILENO, F_SETFL, file_flags);
} }
} }

View File

@ -7,7 +7,7 @@
* handling, unlimited command length, long line handling) added Apr 1999 by * handling, unlimited command length, long line handling) added Apr 1999 by
* Mike Coleman <mkc@acm.org>. * Mike Coleman <mkc@acm.org>.
* *
* Changes by Albert Cahalan, 2002. * Changes by Albert Cahalan, 2002-2003.
*/ */
#define VERSION "0.2.0" #define VERSION "0.2.0"