aboutsummaryrefslogtreecommitdiffstats
path: root/ProcessList.c
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2016-04-11 13:00:18 +0200
committerDaniel Lange <DLange@git.local>2016-04-11 13:00:18 +0200
commit031c3bb95f3d0a74d985286068baa6dd4d29d83f (patch)
treef8258f898976e17dfbc9df30ca357be6cb3605a5 /ProcessList.c
parentbb3dd9e92f5a33ba5dd1192edc1671192e63cc8e (diff)
downloaddebian_htop-031c3bb95f3d0a74d985286068baa6dd4d29d83f.tar.gz
debian_htop-031c3bb95f3d0a74d985286068baa6dd4d29d83f.tar.bz2
debian_htop-031c3bb95f3d0a74d985286068baa6dd4d29d83f.zip
Imported Upstream version 0.5.3upstream/0.5.3
Diffstat (limited to 'ProcessList.c')
-rw-r--r--ProcessList.c50
1 files changed, 12 insertions, 38 deletions
diff --git a/ProcessList.c b/ProcessList.c
index 25d4482..93394fb 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -77,11 +77,6 @@ typedef struct ProcessList_ {
long int usedSwap;
long int freeSwap;
- int kernelMajor;
- int kernelMiddle;
- int kernelMinor;
- int kernelTiny;
-
ProcessField* fields;
ProcessField sortKey;
int direction;
@@ -96,19 +91,6 @@ typedef struct ProcessList_ {
} ProcessList;
}*/
-/* private */
-void ProcessList_getKernelVersion(ProcessList* this) {
- struct utsname uts;
- (void) uname(&uts);
- char** items = String_split(uts.release, '.');
- this->kernelMajor = atoi(items[0]);
- this->kernelMiddle = atoi(items[1]);
- this->kernelMinor = atoi(items[2]);
- this->kernelTiny = items[3] ? atoi(items[3]) : 0;
- for (int i = 0; items[i] != NULL; i++) free(items[i]);
- free(items);
-}
-
/* private property */
ProcessField defaultHeaders[LAST_PROCESSFIELD] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, LAST_PROCESSFIELD };
@@ -125,8 +107,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
this->processes2 = TypedVector_new(PROCESS_CLASS, true, DEFAULT_SIZE);
TypedVector_setCompareFunction(this->processes2, Process_compare);
- ProcessList_getKernelVersion(this);
-
FILE* status = fopen(PROCSTATFILE, "r");
assert(status != NULL);
char buffer[256];
@@ -562,25 +542,19 @@ void ProcessList_scan(ProcessList* this) {
assert(status != NULL);
for (int i = 0; i <= this->processorCount; i++) {
int cpuid;
- if (this->kernelMajor == 2 && this->kernelMiddle <= 4) {
- if (i == 0) {
- fscanf(status, "cpu %ld %ld %ld %ld\n", &usertime, &nicetime, &systemtime, &idletime);
- } else {
- fscanf(status, "cpu%d %ld %ld %ld %ld\n", &cpuid, &usertime, &nicetime, &systemtime, &idletime);
- assert(cpuid == i - 1);
- }
- totaltime = usertime + nicetime + systemtime + idletime;
- } else {
- long int ioWait, irq, softIrq;
- if (i == 0)
- fscanf(status, "cpu %ld %ld %ld %ld %ld %ld %ld\n", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq);
- else {
- fscanf(status, "cpu%d %ld %ld %ld %ld %ld %ld %ld\n", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq);
- assert(cpuid == i - 1);
- }
- systemtime += ioWait + irq + softIrq;
- totaltime = usertime + nicetime + systemtime + idletime;
+ int fieldsread;
+ long int ioWait, irq, softIrq, steal;
+ ioWait = irq = softIrq = steal = 0;
+ if (i == 0)
+ fieldsread = fscanf(status, "cpu %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);
+ assert(cpuid == i - 1);
}
+ // Fields existing on kernels >= 2.6
+ // (and RHEL's patched kernel 2.4...)
+ systemtime += ioWait + irq + softIrq + steal;
+ totaltime = usertime + nicetime + systemtime + idletime;
assert (usertime >= this->userTime[i]);
assert (nicetime >= this->niceTime[i]);
assert (systemtime >= this->systemTime[i]);

© 2014-2024 Faster IT GmbH | imprint | privacy policy