Hi,
I just wanted to let you know about a change I did to
my local wmtop installation today. After about 128
days of uptime on my Linux box, "cat /proc/stat |
head -1" gave me output like this:
cpu 38943913 1527201 36333119 2151752279
so I got a integer overflow in calc_cpu_total(). The
below patch worked for me, in case you want to do
something along the same lines yourself. Thank you.
Erik Forkalsrud
erik@cj.com
--- wmtop.c.orig Mon Oct 1 10:07:33 2001
+++ wmtop.c Mon Oct 1 10:07:43 2001
@@ -787,20 +787,20 @@
/******************************************/
int calc_cpu_total() {
- int total,t;
- static int previous_total = INT_MAX;
+ long long total,t;
+ static long long previous_total = INT_MAX;
#if defined(LINUX)
int rc;
int ps;
char line[WMTOP_BUFLENGTH];
- int cpu,nice,system,idle;
+ long long cpu,nice,system,idle;
ps = open("/proc/stat",O_RDONLY);
rc = read(ps,line,sizeof(line));
close(ps);
if (rc<0)
return 0;
- sscanf(line,"%*s %d %d %d
%d",&cpu,&nice,&system,&idle);
+ sscanf(line,"%*s %Ld %Ld %Ld
%Ld",&cpu,&nice,&system,&idle);
total = cpu+nice+system+idle;
#endif /* defined(LINUX) */