top: do not refresh like crazy
This commit is contained in:
parent
7775a65c4d
commit
1351592110
4
NEWS
4
NEWS
@ -2,6 +2,10 @@ procps-3.1.6 --> procps-3.1.7
|
||||
|
||||
watch: --help now explains -t, --no-title #182246
|
||||
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
|
||||
|
||||
|
5
README
5
README
@ -1,7 +1,8 @@
|
||||
COMPATIBILITY
|
||||
|
||||
This code is intended for use with Linux 2.0.xx and above.
|
||||
Both libc 5 and libc 6 should work.
|
||||
This code is intended for use with Linux 2.2.xx, 2.4.xx,
|
||||
2.5.xx, and hopefully all future kernels. You should be
|
||||
running a system with libc 6, but libc 5 might work too.
|
||||
|
||||
INSTALLATION
|
||||
|
||||
|
@ -266,7 +266,7 @@ hell:
|
||||
*bufp = NULL;
|
||||
*roomp = 0; /* this function will never work again */
|
||||
total = 0;
|
||||
close(fd);
|
||||
if(fd>0) close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ global:
|
||||
display_version; procps_version; linux_version_code;
|
||||
Hertz; smp_num_cpus;
|
||||
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;
|
||||
kb_active; kb_inactive; kb_main_buffers; kb_main_cached;
|
||||
kb_main_free; kb_main_total; kb_main_used; kb_swap_free;
|
||||
|
@ -146,7 +146,7 @@ int signal_name_to_number(const char *restrict name){
|
||||
return val+offset;
|
||||
}
|
||||
|
||||
static const char *signal_number_to_name(int signo){
|
||||
const char *signal_number_to_name(int signo){
|
||||
static char buf[32];
|
||||
int n = number_of_signals;
|
||||
signo &= 0x7f; /* need to process exit values too */
|
||||
|
@ -18,6 +18,8 @@ EXTERN_C_BEGIN
|
||||
/* return -1 on failure */
|
||||
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 void pretty_print_signals(void);
|
||||
|
@ -40,9 +40,10 @@ static void signal_handler(int signo){
|
||||
/* fprintf() is not reentrant, but we _exit() anyway */
|
||||
fprintf(stderr,
|
||||
"\n\n"
|
||||
"Signal %d caught by ps (%s).\n"
|
||||
"Please send bug reports to <acahalan@cs.uml.edu>\n",
|
||||
"Signal %d (%s) caught by ps (%s).\n"
|
||||
"Please send bug reports to <feedback@lists.sf.net> or <albert@users.sf.net>\n",
|
||||
signo,
|
||||
signal_number_to_name(signo),
|
||||
procps_version
|
||||
);
|
||||
_exit(signo+128);
|
||||
|
@ -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
|
||||
* GNU Library General Public License Version 2, or any later version
|
||||
* at your option, as published by the Free Software Foundation.
|
||||
|
48
top.c
48
top.c
@ -87,6 +87,10 @@ static int Monpidsidx = 0;
|
||||
static char Msg_delayed [SMLBUFSIZ];
|
||||
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 ##################################*/
|
||||
|
||||
/* Current screen dimensions.
|
||||
@ -437,6 +441,7 @@ static void suspend (int dont_care_sig)
|
||||
fflush(stdout);
|
||||
raise(SIGSTOP);
|
||||
/* later, after SIGCONT... */
|
||||
ZAP_TIMEOUT
|
||||
if (!Batch)
|
||||
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
|
||||
Frames_libflags = 0;
|
||||
ZAP_TIMEOUT
|
||||
}
|
||||
|
||||
|
||||
@ -2804,7 +2810,12 @@ static proc_t **summary_show (void)
|
||||
if (!p_table) {
|
||||
p_table = procs_refresh(NULL, Frames_libflags);
|
||||
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
|
||||
putp(Batch ? "\n\n" : Cap_home);
|
||||
p_table = procs_refresh(p_table, Frames_libflags);
|
||||
@ -2812,13 +2823,14 @@ static proc_t **summary_show (void)
|
||||
/*
|
||||
** Display Uptime and Loadavg */
|
||||
if (CHKw(Curwin, View_LOADAV)) {
|
||||
if (!Rc.mode_altscr)
|
||||
if (!Rc.mode_altscr) {
|
||||
show_special(0, fmtmk(LOADAV_line, Myname, sprint_uptime()));
|
||||
else
|
||||
} else {
|
||||
show_special(0, fmtmk(CHKw(Curwin, VISIBLE_tsk)
|
||||
? LOADAV_line_alt
|
||||
: LOADAV_line
|
||||
, Curwin->grpname, sprint_uptime()));
|
||||
}
|
||||
Msg_row += 1;
|
||||
}
|
||||
|
||||
@ -3228,26 +3240,30 @@ int main (int dont_care_argc, char **argv)
|
||||
signal(SIGWINCH, wins_resize);
|
||||
|
||||
for (;;) {
|
||||
struct timeval tv;
|
||||
fd_set fs;
|
||||
char c;
|
||||
// This is it?
|
||||
frame_make(); // Impossible!
|
||||
frame_make();
|
||||
|
||||
if (Msg_awaiting) show_msg(Msg_delayed);
|
||||
if (0 < Loops) --Loops;
|
||||
if (!Loops) end_pgm(0);
|
||||
|
||||
if (Batch)
|
||||
sleep((unsigned)Rc.delay_time);
|
||||
else { // Linux reports time not slept,
|
||||
tv.tv_sec = Rc.delay_time; // so we must reinit every time.
|
||||
tv.tv_usec = (Rc.delay_time - (int)Rc.delay_time) * 1000000;
|
||||
tv.tv_sec = Rc.delay_time;
|
||||
tv.tv_usec = (Rc.delay_time - (int)Rc.delay_time) * 1000000;
|
||||
|
||||
if (Batch) {
|
||||
select(0, NULL, NULL, NULL, &tv); // ought to loop until done
|
||||
} else {
|
||||
long file_flags;
|
||||
char c;
|
||||
fd_set fs;
|
||||
FD_ZERO(&fs);
|
||||
FD_SET(STDIN_FILENO, &fs);
|
||||
if (0 < select(STDIN_FILENO+1, &fs, NULL, NULL, &tv)
|
||||
&& 0 < chin(0, &c, 1))
|
||||
do_key((unsigned)c);
|
||||
file_flags = fcntl(STDIN_FILENO, F_GETFL);
|
||||
if(file_flags==-1) file_flags=0;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user