]> granicus.if.org Git - procps-ng/commitdiff
top: do not refresh like crazy
authoralbert <>
Mon, 17 Mar 2003 23:42:00 +0000 (23:42 +0000)
committeralbert <>
Mon, 17 Mar 2003 23:42:00 +0000 (23:42 +0000)
NEWS
README
proc/ksym.c
proc/library.map
proc/sig.c
proc/sig.h
ps/display.c
ps/parser.c
top.c
watch.c

diff --git a/NEWS b/NEWS
index 9c5b2a62c1fdb40bd0f52e9c04a08edb0ee15cad..dfb08b597141a9b37646120fd66f3692cc448fec 100644 (file)
--- a/NEWS
+++ b/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
 
diff --git a/README b/README
index e4f1aef408d02b740ffce86e03176a99ad199d17..7da1658a2188e7425e5e7cc9b37c249018738af4 100644 (file)
--- a/README
+++ b/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
 
index b38fe3840f27d7cb401d49e38ffd0a44433dab56..3b156e97b70a51dd0e3161ff09a65e3b07294a51 100644 (file)
@@ -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;
 }
 
index dfca5cecb121845c9dcf9c49909065ffea22fd70..32e9d84cd15fa8b27274203049be61f3d287b5a0 100644 (file)
@@ -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;
index ca41c6a1510f23a5b30942560eda23b03355ed9f..18e839a9f2a920ff51d118cd48e570837216d4a4 100644 (file)
@@ -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 */
index d9518e5ac1dbe0a4c0b33a531a4edf3c8de6c4ac..ccb6c43a2ff9834f94a9c4eec305cb8dee040049 100644 (file)
@@ -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);
index 2437a215e4412840d14d4ac4369244262704d7b7..226eb403e5ef97d584038d8017082f86ee02fac9 100644 (file)
@@ -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);
index a0d0edd91ba1772985ebde8ceaf67a975d2e3f6a..decdc1d4c1ebc32b6074f92fc10aab290fbc8d27 100644 (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
  * GNU Library General Public License Version 2, or any later version
  * at your option, as published by the Free Software Foundation.
diff --git a/top.c b/top.c
index 2df800d393d7d2226d04a04edfdc7fd4bf553bd6..7cff4dfd9470eb1f62d3db899c1d014302de69fa 100644 (file)
--- a/top.c
+++ b/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);
       }
    }
 
diff --git a/watch.c b/watch.c
index a55514f508b9d55fd40e250d60ec8867ed9e7112..deec46239f17099ca2db7d5e87e18836a2b87bca 100644 (file)
--- a/watch.c
+++ b/watch.c
@@ -7,7 +7,7 @@
  * handling, unlimited command length, long line handling) added Apr 1999 by
  * Mike Coleman <mkc@acm.org>.
  *
- * Changes by Albert Cahalan, 2002.
+ * Changes by Albert Cahalan, 2002-2003.
  */
 
 #define VERSION "0.2.0"