mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
top.c: fix for unsigned underflow
Yes, I also thought these are monotonic counters. But it seems like they are not, at least sometimes the value decreases by 1 leading to a very very high cpu usage percentage being printed.
This commit is contained in:
parent
7fa59c6c90
commit
fea72bd8f8
@ -167,6 +167,7 @@ static int process_parse_stat(struct process *process)
|
||||
"%lu %*s %*s %*s %d %*s %*s %*s %u %u", &process->user_time,
|
||||
&process->kernel_time, &nice_val, &process->vsize, &process->rss);
|
||||
if (rc < 5) {
|
||||
NORM_ERR("scaning data for %s failed, got only %d fields", procname, rc);
|
||||
return 1;
|
||||
}
|
||||
/* remove any "kdeinit: " */
|
||||
@ -219,6 +220,13 @@ static int process_parse_stat(struct process *process)
|
||||
process->previous_kernel_time = process->kernel_time;
|
||||
}
|
||||
|
||||
/* strangely, the values aren't monotonous */
|
||||
if (process->previous_user_time > process->user_time)
|
||||
process->previous_user_time = process->user_time;
|
||||
|
||||
if (process->previous_kernel_time > process->kernel_time)
|
||||
process->previous_kernel_time = process->kernel_time;
|
||||
|
||||
/* store the difference of the user_time */
|
||||
user_time = process->user_time - process->previous_user_time;
|
||||
kernel_time = process->kernel_time - process->previous_kernel_time;
|
||||
|
Loading…
Reference in New Issue
Block a user