]> granicus.if.org Git - procps-ng/commitdiff
top: avoid a 'nan' when the delay interval is very low
authorJim Warner <james.warner@comcast.net>
Sun, 27 Apr 2014 05:00:00 +0000 (00:00 -0500)
committerJaromir Capik <jcapik@redhat.com>
Mon, 28 Apr 2014 18:56:48 +0000 (20:56 +0200)
The granularity of /proc/uptime is fixed at hundredths
of a second. And, since we can cycle faster than that,
we are exposed to 'nan' when calculating elapsed time.

This commit will protect us from that outcome when the
delay interval has been set to an extremely low value.

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 0428496f4bbbc06882f332551fd95d81576c80d4..0ae538857bc5affafcd0da1c905a94e3ea5784a7 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -2525,6 +2525,7 @@ static void procs_hlp (proc_t *this) {
 
       uptime(&uptime_cur, NULL);
       et = uptime_cur - uptime_sav;
+      if (et < 0.01) et = 0.005;
       uptime_sav = uptime_cur;
 
       // if in Solaris mode, adjust our scaling for all cpus