From 2c8c1a156130aa40be7dcaeb3ce2977a03cf50c2 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:18 +0200 Subject: Imported Upstream version 0.5.4 --- ProcessList.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ProcessList.c') diff --git a/ProcessList.c b/ProcessList.c index 93394fb..d5d4ddc 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -1,6 +1,6 @@ /* -htop -(C) 2004 Hisham H. Muhammad +htop - ProcessList.c +(C) 2004,2005 Hisham H. Muhammad Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ @@ -541,14 +541,18 @@ void ProcessList_scan(ProcessList* this) { status = fopen(PROCSTATFILE, "r"); assert(status != NULL); for (int i = 0; i <= this->processorCount; i++) { + char buffer[256]; int cpuid; - int fieldsread; long int ioWait, irq, softIrq, steal; ioWait = irq = softIrq = steal = 0; + // Dependending on your kernel version, + // 5, 7 or 8 of these fields will be set. + // The rest will remain at zero. + fgets(buffer, 255, status); if (i == 0) - fieldsread = fscanf(status, "cpu %ld %ld %ld %ld %ld %ld %ld\n", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); + sscanf(buffer, "cpu %ld %ld %ld %ld %ld %ld %ld %ld\n", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); else { - fieldsread = fscanf(status, "cpu%d %ld %ld %ld %ld %ld %ld %ld\n", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); + sscanf(buffer, "cpu%d %ld %ld %ld %ld %ld %ld %ld %ld\n", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal); assert(cpuid == i - 1); } // Fields existing on kernels >= 2.6 -- cgit v1.2.3