1 Commits
0.6.6 ... 0.6.4

Author SHA1 Message Date
0384613450 Tag release 0.6.4 in revision history 2006-10-06 23:07:46 +00:00
18 changed files with 146 additions and 315 deletions

View File

@ -1,33 +1,3 @@
What's new in version 0.6.6
* Add support of NLWP field
(thanks to Bert Wesarg)
* BUGFIX: Fix use of configurable /proc location
(thanks to Florent Thoumie)
* Fix memory percentage calculation and make it saner
(thanks to Olev Kartau for the report)
* Added display of DRS, DT, LRS and TRS
(thanks to Matthias Lederhofer)
* BUGFIX: LRS and DRS memory values were flipped
(thanks to Matthias Lederhofer)
* BUGFIX: Don't crash on very high UIDs
(thanks to Egmont Koblinger)
What's new in version 0.6.5
* Add hardened-debug flags for debugging with Hardened GCC
* BUGFIX: Handle error condition when a directory vanishes
from /proc
* BUGFIX: Fix leak of process command line
* BUGFIX: Collect orphaned items when arranging the tree view.
(thanks to Wolfram Schlich for assistance with debugging)
* Separate proc and memory debugging into separate #defines.
* BUGFIX: Fix message when configure fails due to
missing libraries
(thanks to Jon)
* BUGFIX: Don't truncate value when displaying a very large
process
(thanks to Bo Liu)
What's new in version 0.6.4 What's new in version 0.6.4

View File

@ -49,11 +49,7 @@ void DebugMemory_new() {
singleton->allocations = 0; singleton->allocations = 0;
singleton->deallocations = 0; singleton->deallocations = 0;
singleton->size = 0; singleton->size = 0;
#ifdef DEBUG_ALLOC
singleton->file = fopen("/tmp/htop-debug-alloc.txt", "w"); singleton->file = fopen("/tmp/htop-debug-alloc.txt", "w");
#else
singleton->file = NULL;
#endif
singleton->totals = true; singleton->totals = true;
//singleton->file = NULL; //singleton->file = NULL;
} }

View File

@ -9,7 +9,6 @@ in the source distribution for its full text.
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#include "debug.h" #include "debug.h"
@ -19,7 +18,7 @@ typedef struct Hashtable_ Hashtable;
typedef void(*Hashtable_PairFunction)(int, void*, void*); typedef void(*Hashtable_PairFunction)(int, void*, void*);
typedef struct HashtableItem { typedef struct HashtableItem {
unsigned int key; int key;
void* value; void* value;
struct HashtableItem* next; struct HashtableItem* next;
} HashtableItem; } HashtableItem;
@ -32,36 +31,7 @@ struct Hashtable_ {
}; };
}*/ }*/
#ifdef DEBUG HashtableItem* HashtableItem_new(int key, void* value) {
bool Hashtable_isConsistent(Hashtable* this) {
int items = 0;
for (int i = 0; i < this->size; i++) {
HashtableItem* bucket = this->buckets[i];
while (bucket) {
items++;
bucket = bucket->next;
}
}
return items == this->items;
}
int Hashtable_count(Hashtable* this) {
int items = 0;
for (int i = 0; i < this->size; i++) {
HashtableItem* bucket = this->buckets[i];
while (bucket) {
items++;
bucket = bucket->next;
}
}
assert(items == this->items);
return items;
}
#endif
HashtableItem* HashtableItem_new(unsigned int key, void* value) {
HashtableItem* this; HashtableItem* this;
this = (HashtableItem*) malloc(sizeof(HashtableItem)); this = (HashtableItem*) malloc(sizeof(HashtableItem));
@ -75,16 +45,13 @@ Hashtable* Hashtable_new(int size, bool owner) {
Hashtable* this; Hashtable* this;
this = (Hashtable*) malloc(sizeof(Hashtable)); this = (Hashtable*) malloc(sizeof(Hashtable));
this->items = 0;
this->size = size; this->size = size;
this->buckets = (HashtableItem**) calloc(sizeof(HashtableItem*), size); this->buckets = (HashtableItem**) calloc(sizeof(HashtableItem*), size);
this->owner = owner; this->owner = owner;
assert(Hashtable_isConsistent(this));
return this; return this;
} }
void Hashtable_delete(Hashtable* this) { void Hashtable_delete(Hashtable* this) {
assert(Hashtable_isConsistent(this));
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
HashtableItem* walk = this->buckets[i]; HashtableItem* walk = this->buckets[i];
while (walk != NULL) { while (walk != NULL) {
@ -100,12 +67,11 @@ void Hashtable_delete(Hashtable* this) {
} }
inline int Hashtable_size(Hashtable* this) { inline int Hashtable_size(Hashtable* this) {
assert(Hashtable_isConsistent(this));
return this->items; return this->items;
} }
void Hashtable_put(Hashtable* this, unsigned int key, void* value) { void Hashtable_put(Hashtable* this, int key, void* value) {
unsigned int index = key % this->size; int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]); HashtableItem** bucketPtr = &(this->buckets[index]);
while (true) while (true)
if (*bucketPtr == NULL) { if (*bucketPtr == NULL) {
@ -119,53 +85,47 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
break; break;
} else } else
bucketPtr = &((*bucketPtr)->next); bucketPtr = &((*bucketPtr)->next);
assert(Hashtable_isConsistent(this));
} }
void* Hashtable_remove(Hashtable* this, unsigned int key) { void* Hashtable_remove(Hashtable* this, int key) {
unsigned int index = key % this->size; int index = key % this->size;
HashtableItem** bucketPtr = &(this->buckets[index]);
assert(Hashtable_isConsistent(this)); while (true)
if (*bucketPtr == NULL) {
HashtableItem** bucket; return NULL;
for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) { break;
if ((*bucket)->key == key) { } else if ((*bucketPtr)->key == key) {
void* value = (*bucket)->value; void* savedValue = (*bucketPtr)->value;
HashtableItem* next = (*bucket)->next; HashtableItem* savedNext = (*bucketPtr)->next;
free(*bucket); free(*bucketPtr);
(*bucket) = next; (*bucketPtr) = savedNext;
this->items--; this->items--;
if (this->owner) { if (this->owner) {
free(value); free(savedValue);
assert(Hashtable_isConsistent(this));
return NULL; return NULL;
} else { } else {
assert(Hashtable_isConsistent(this)); return savedValue;
return value;
} }
} } else
} bucketPtr = &((*bucketPtr)->next);
assert(Hashtable_isConsistent(this));
return NULL;
} }
//#include <stdio.h>
inline void* Hashtable_get(Hashtable* this, unsigned int key) { inline void* Hashtable_get(Hashtable* this, int key) {
unsigned int index = key % this->size; int index = key % this->size;
HashtableItem* bucketPtr = this->buckets[index]; HashtableItem* bucketPtr = this->buckets[index];
// fprintf(stderr, "%d -> %d\n", key, index);
while (true) { while (true) {
if (bucketPtr == NULL) { if (bucketPtr == NULL) {
assert(Hashtable_isConsistent(this));
return NULL; return NULL;
} else if (bucketPtr->key == key) { } else if (bucketPtr->key == key) {
assert(Hashtable_isConsistent(this));
return bucketPtr->value; return bucketPtr->value;
} else } else
bucketPtr = bucketPtr->next; bucketPtr = bucketPtr->next;
// fprintf(stderr, "*\n");
} }
} }
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) { void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) {
assert(Hashtable_isConsistent(this));
for (int i = 0; i < this->size; i++) { for (int i = 0; i < this->size; i++) {
HashtableItem* walk = this->buckets[i]; HashtableItem* walk = this->buckets[i];
while (walk != NULL) { while (walk != NULL) {
@ -173,5 +133,4 @@ void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData
walk = walk->next; walk = walk->next;
} }
} }
assert(Hashtable_isConsistent(this));
} }

View File

@ -12,7 +12,6 @@ in the source distribution for its full text.
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#include "debug.h" #include "debug.h"
@ -21,7 +20,7 @@ typedef struct Hashtable_ Hashtable;
typedef void(*Hashtable_PairFunction)(int, void*, void*); typedef void(*Hashtable_PairFunction)(int, void*, void*);
typedef struct HashtableItem { typedef struct HashtableItem {
unsigned int key; int key;
void* value; void* value;
struct HashtableItem* next; struct HashtableItem* next;
} HashtableItem; } HashtableItem;
@ -33,15 +32,7 @@ struct Hashtable_ {
bool owner; bool owner;
}; };
#ifdef DEBUG HashtableItem* HashtableItem_new(int key, void* value);
bool Hashtable_isConsistent(Hashtable* this);
int Hashtable_count(Hashtable* this);
#endif
HashtableItem* HashtableItem_new(unsigned int key, void* value);
Hashtable* Hashtable_new(int size, bool owner); Hashtable* Hashtable_new(int size, bool owner);
@ -49,11 +40,11 @@ void Hashtable_delete(Hashtable* this);
inline int Hashtable_size(Hashtable* this); inline int Hashtable_size(Hashtable* this);
void Hashtable_put(Hashtable* this, unsigned int key, void* value); void Hashtable_put(Hashtable* this, int key, void* value);
void* Hashtable_remove(Hashtable* this, unsigned int key); void* Hashtable_remove(Hashtable* this, int key);
//#include <stdio.h>
inline void* Hashtable_get(Hashtable* this, unsigned int key); inline void* Hashtable_get(Hashtable* this, int key);
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData); void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);

View File

@ -11,42 +11,28 @@ pixmap_DATA = htop.png
AM_CFLAGS = -pedantic -Wall -std=c99 AM_CFLAGS = -pedantic -Wall -std=c99
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ htop_SOURCES = AvailableMetersPanel.c CategoriesPanel.c ClockMeter.c \
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DebugMemory.c \ CPUMeter.c CRT.c DebugMemory.c DisplayOptionsPanel.c FunctionBar.c \
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ Hashtable.c Header.c htop.c Panel.c ListItem.c LoadAverageMeter.c \
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ MemoryMeter.c Meter.c MetersPanel.c Object.c Process.c \
Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \
SignalItem.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \ SignalsPanel.c String.c SwapMeter.c TasksMeter.c Vector.c \
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c UptimeMeter.c UsersTable.c AvailableMetersPanel.h CategoriesPanel.h \
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ DisplayOptionsPanel.h FunctionBar.h Hashtable.h Header.h htop.h Panel.h \
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \
CPUMeter.h CRT.h DebugMemory.h DisplayOptionsPanel.h FunctionBar.h \ MetersPanel.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ Settings.h SignalItem.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \
ScreenManager.h Settings.h SignalItem.h SignalsPanel.h String.h \ ColorsPanel.c ColorsPanel.h TraceScreen.c TraceScreen.h \
SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \ AvailableColumnsPanel.c AvailableColumnsPanel.h ColumnsPanel.c \
Process.h ColumnsPanel.h
SUFFIXES = .h
BUILT_SOURCES = $(myhtopheaders)
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h
profile: profile:
$(MAKE) all CFLAGS="-pg -O2" $(MAKE) all CFLAGS="-pg -O2"
debug: debug:
$(MAKE) all CFLAGS="-ggdb -DDEBUG" $(MAKE) all CFLAGS="-g -DDEBUG"
hardened-debug:
$(MAKE) all CFLAGS="-ggdb -DDEBUG" LDFLAGS="-nopie"
debuglite: debuglite:
$(MAKE) all CFLAGS="-ggdb -DDEBUGLITE" $(MAKE) all CFLAGS="-g -DDEBUGLITE"
.c.h:
scripts/MakeHeader.py $<

View File

@ -28,9 +28,7 @@ in the source distribution for its full text.
// This works only with glibc 2.1+. On earlier versions // This works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size. // the behavior is similar to have a hardcoded page size.
#ifndef PAGE_SIZE
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 ) #define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
#endif
#define PROCESS_COMM_LEN 300 #define PROCESS_COMM_LEN 300
@ -41,7 +39,7 @@ typedef enum ProcessField_ {
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE, STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL, STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM, PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, LAST_PROCESSFIELD USER, TIME, LAST_PROCESSFIELD
} ProcessField; } ProcessField;
struct ProcessList_; struct ProcessList_;
@ -52,16 +50,16 @@ typedef struct Process_ {
struct ProcessList_ *pl; struct ProcessList_ *pl;
bool updated; bool updated;
unsigned int pid; int pid;
char* comm; char* comm;
int indent; int indent;
char state; char state;
bool tag; bool tag;
unsigned int ppid; int ppid;
unsigned int pgrp; int pgrp;
unsigned int session; int session;
unsigned int tty_nr; int tty_nr;
unsigned int tpgid; int tpgid;
unsigned long int flags; unsigned long int flags;
#ifdef DEBUG #ifdef DEBUG
unsigned long int minflt; unsigned long int minflt;
@ -75,7 +73,6 @@ typedef struct Process_ {
long int cstime; long int cstime;
long int priority; long int priority;
long int nice; long int nice;
long int nlwp;
#ifdef DEBUG #ifdef DEBUG
long int itrealvalue; long int itrealvalue;
unsigned long int starttime; unsigned long int starttime;
@ -119,7 +116,7 @@ char* PROCESS_CLASS = "Process";
#endif #endif
char *Process_fieldNames[] = { char *Process_fieldNames[] = {
"", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", "STARTTIME", "VSIZE", "RSS", "RLIM", "STARTCODE", "ENDCODE", "STARTSTACK", "KSTKESP", "KSTKEIP", "SIGNAL", "BLOCKED", "SIGIGNORE", "SIGCATCH", "WCHAN", "NSWAP", "CNSWAP", "EXIT_SIGNAL", "PROCESSOR", "M_SIZE", "M_RESIDENT", "M_SHARE", "M_TRS", "M_DRS", "M_LRS", "M_DT", "ST_UID", "PERCENT_CPU", "PERCENT_MEM", "USER", "TIME", "NLWP", "*** report bug! ***" "", "PID", "Command", "STATE", "PPID", "PGRP", "SESSION", "TTY_NR", "TPGID", "FLAGS", "MINFLT", "CMINFLT", "MAJFLT", "CMAJFLT", "UTIME", "STIME", "CUTIME", "CSTIME", "PRIORITY", "NICE", "ITREALVALUE", "STARTTIME", "VSIZE", "RSS", "RLIM", "STARTCODE", "ENDCODE", "STARTSTACK", "KSTKESP", "KSTKEIP", "SIGNAL", "BLOCKED", "SIGIGNORE", "SIGCATCH", "WCHAN", "NSWAP", "CNSWAP", "EXIT_SIGNAL", "PROCESSOR", "M_SIZE", "M_RESIDENT", "M_SHARE", "M_TRS", "M_DRS", "M_LRS", "M_DT", "ST_UID", "PERCENT_CPU", "PERCENT_MEM", "USER", "TIME", "*** report bug! ***"
}; };
static int Process_getuid = -1; static int Process_getuid = -1;
@ -129,14 +126,12 @@ Process* Process_new(struct ProcessList_ *pl) {
Object_setClass(this, PROCESS_CLASS); Object_setClass(this, PROCESS_CLASS);
((Object*)this)->display = Process_display; ((Object*)this)->display = Process_display;
((Object*)this)->delete = Process_delete; ((Object*)this)->delete = Process_delete;
this->pid = 0;
this->pl = pl; this->pl = pl;
this->tag = false; this->tag = false;
this->updated = false; this->updated = false;
this->utime = 0; this->utime = 0;
this->stime = 0; this->stime = 0;
this->comm = NULL; this->comm = NULL;
this->indent = 0;
if (Process_getuid == -1) Process_getuid = getuid(); if (Process_getuid == -1) Process_getuid = getuid();
return this; return this;
} }
@ -144,15 +139,13 @@ Process* Process_new(struct ProcessList_ *pl) {
Process* Process_clone(Process* this) { Process* Process_clone(Process* this) {
Process* clone = malloc(sizeof(Process)); Process* clone = malloc(sizeof(Process));
memcpy(clone, this, sizeof(Process)); memcpy(clone, this, sizeof(Process));
this->comm = NULL;
this->pid = 0;
return clone; return clone;
} }
void Process_delete(Object* cast) { void Process_delete(Object* cast) {
Process* this = (Process*) cast; Process* this = (Process*) cast;
assert (this != NULL);
if (this->comm) free(this->comm); if (this->comm) free(this->comm);
assert (this != NULL);
free(this); free(this);
} }
@ -189,26 +182,26 @@ void Process_sendSignal(Process* this, int signal) {
#define ONE_M (ONE_K * ONE_K) #define ONE_M (ONE_K * ONE_K)
#define ONE_G (ONE_M * ONE_K) #define ONE_G (ONE_M * ONE_K)
static void Process_printLargeNumber(Process* this, RichString *str, unsigned long number) { static void Process_printLargeNumber(Process* this, RichString *str, unsigned int number) {
char buffer[11]; char buffer[11];
int len; int len;
if(number >= (1000 * ONE_M)) { if(number >= (1000 * ONE_M)) {
len = snprintf(buffer, 10, "%4.2fG ", (float)number / ONE_M); len = snprintf(buffer, 10, "%4.2fG ", (float)number / ONE_M);
RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, len); RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, len);
} else if(number >= (100000)) { } else if(number >= (100000)) {
len = snprintf(buffer, 10, "%4ldM ", number / ONE_K); len = snprintf(buffer, 10, "%4dM ", number / ONE_K);
int attr = this->pl->highlightMegabytes int attr = this->pl->highlightMegabytes
? CRT_colors[PROCESS_MEGABYTES] ? CRT_colors[PROCESS_MEGABYTES]
: CRT_colors[PROCESS]; : CRT_colors[PROCESS];
RichString_appendn(str, attr, buffer, len); RichString_appendn(str, attr, buffer, len);
} else if (this->pl->highlightMegabytes && number >= 1000) { } else if (this->pl->highlightMegabytes && number >= 1000) {
len = snprintf(buffer, 10, "%2ld", number/1000); len = snprintf(buffer, 10, "%2d", number/1000);
RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer, len); RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer, len);
number %= 1000; number %= 1000;
len = snprintf(buffer, 10, "%03ld ", number); len = snprintf(buffer, 10, "%03d ", number);
RichString_appendn(str, CRT_colors[PROCESS], buffer, len); RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
} else { } else {
len = snprintf(buffer, 10, "%5ld ", number); len = snprintf(buffer, 10, "%5d ", number);
RichString_appendn(str, CRT_colors[PROCESS], buffer, len); RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
} }
} }
@ -264,14 +257,13 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
int n = PROCESS_COMM_LEN; int n = PROCESS_COMM_LEN;
switch (field) { switch (field) {
case PID: snprintf(buffer, n, "%5u ", this->pid); break; case PID: snprintf(buffer, n, "%5d ", this->pid); break;
case PPID: snprintf(buffer, n, "%5u ", this->ppid); break; case PPID: snprintf(buffer, n, "%5d ", this->ppid); break;
case PGRP: snprintf(buffer, n, "%5u ", this->pgrp); break; case PGRP: snprintf(buffer, n, "%5d ", this->pgrp); break;
case SESSION: snprintf(buffer, n, "%5u ", this->session); break; case SESSION: snprintf(buffer, n, "%5d ", this->session); break;
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break; case TTY_NR: snprintf(buffer, n, "%5d ", this->tty_nr); break;
case TPGID: snprintf(buffer, n, "%5u ", this->tpgid); break; case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break; case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break;
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
case COMM: { case COMM: {
if (!this->pl->treeView || this->indent == 0) { if (!this->pl->treeView || this->indent == 0) {
Process_writeCommand(this, attr, str); Process_writeCommand(this, attr, str);
@ -320,10 +312,6 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
: attr; : attr;
break; break;
} }
case M_DRS: Process_printLargeNumber(this, str, this->m_drs * PAGE_SIZE); return;
case M_DT: Process_printLargeNumber(this, str, this->m_dt * PAGE_SIZE); return;
case M_LRS: Process_printLargeNumber(this, str, this->m_lrs * PAGE_SIZE); return;
case M_TRS: Process_printLargeNumber(this, str, this->m_trs * PAGE_SIZE); return;
case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE); return; case M_SIZE: Process_printLargeNumber(this, str, this->m_size * PAGE_SIZE); return;
case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return; case M_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return;
case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return; case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return;
@ -399,14 +387,6 @@ int Process_compare(const void* v1, const void* v2) {
return (p1->state - p2->state); return (p1->state - p2->state);
case NICE: case NICE:
return (p1->nice - p2->nice); return (p1->nice - p2->nice);
case M_DRS:
return (p2->m_drs - p1->m_drs);
case M_DT:
return (p2->m_dt - p1->m_dt);
case M_LRS:
return (p2->m_lrs - p1->m_lrs);
case M_TRS:
return (p2->m_trs - p1->m_trs);
case M_SIZE: case M_SIZE:
return (p2->m_size - p1->m_size); return (p2->m_size - p1->m_size);
case M_RESIDENT: case M_RESIDENT:
@ -425,8 +405,6 @@ int Process_compare(const void* v1, const void* v2) {
return ((p2->utime+p2->stime) - (p1->utime+p1->stime)); return ((p2->utime+p2->stime) - (p1->utime+p1->stime));
case COMM: case COMM:
return strcmp(p1->comm, p2->comm); return strcmp(p1->comm, p2->comm);
case NLWP:
return (p1->nlwp - p2->nlwp);
default: default:
return (p1->pid - p2->pid); return (p1->pid - p2->pid);
} }
@ -445,10 +423,6 @@ char* Process_printField(ProcessField field) {
case STATE: return "S "; case STATE: return "S ";
case PRIORITY: return "PRI "; case PRIORITY: return "PRI ";
case NICE: return " NI "; case NICE: return " NI ";
case M_DRS: return " DATA ";
case M_DT: return " DIRTY ";
case M_LRS: return " LIB ";
case M_TRS: return " CODE ";
case M_SIZE: return " VIRT "; case M_SIZE: return " VIRT ";
case M_RESIDENT: return " RES "; case M_RESIDENT: return " RES ";
case M_SHARE: return " SHR "; case M_SHARE: return " SHR ";
@ -460,7 +434,6 @@ char* Process_printField(ProcessField field) {
case PERCENT_CPU: return "CPU% "; case PERCENT_CPU: return "CPU% ";
case PERCENT_MEM: return "MEM% "; case PERCENT_MEM: return "MEM% ";
case PROCESSOR: return "CPU "; case PROCESSOR: return "CPU ";
case NLWP: return "NLWP ";
default: return "- "; default: return "- ";
} }
} }

View File

@ -31,9 +31,7 @@ in the source distribution for its full text.
// This works only with glibc 2.1+. On earlier versions // This works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size. // the behavior is similar to have a hardcoded page size.
#ifndef PAGE_SIZE
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 ) #define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
#endif
#define PROCESS_COMM_LEN 300 #define PROCESS_COMM_LEN 300
@ -43,7 +41,7 @@ typedef enum ProcessField_ {
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE, STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL, STARTSTACK, KSTKESP, KSTKEIP, SIGNAL, BLOCKED, SSIGIGNORE, SIGCATCH, WCHAN, NSWAP, CNSWAP, EXIT_SIGNAL,
PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM, PROCESSOR, M_SIZE, M_RESIDENT, M_SHARE, M_TRS, M_DRS, M_LRS, M_DT, ST_UID, PERCENT_CPU, PERCENT_MEM,
USER, TIME, NLWP, LAST_PROCESSFIELD USER, TIME, LAST_PROCESSFIELD
} ProcessField; } ProcessField;
struct ProcessList_; struct ProcessList_;
@ -54,16 +52,16 @@ typedef struct Process_ {
struct ProcessList_ *pl; struct ProcessList_ *pl;
bool updated; bool updated;
unsigned int pid; int pid;
char* comm; char* comm;
int indent; int indent;
char state; char state;
bool tag; bool tag;
unsigned int ppid; int ppid;
unsigned int pgrp; int pgrp;
unsigned int session; int session;
unsigned int tty_nr; int tty_nr;
unsigned int tpgid; int tpgid;
unsigned long int flags; unsigned long int flags;
#ifdef DEBUG #ifdef DEBUG
unsigned long int minflt; unsigned long int minflt;
@ -77,7 +75,6 @@ typedef struct Process_ {
long int cstime; long int cstime;
long int priority; long int priority;
long int nice; long int nice;
long int nlwp;
#ifdef DEBUG #ifdef DEBUG
long int itrealvalue; long int itrealvalue;
unsigned long int starttime; unsigned long int starttime;

View File

@ -37,11 +37,11 @@ in the source distribution for its full text.
#endif #endif
#ifndef PROCSTATFILE #ifndef PROCSTATFILE
#define PROCSTATFILE PROCDIR "/stat" #define PROCSTATFILE "/proc/stat"
#endif #endif
#ifndef PROCMEMINFOFILE #ifndef PROCMEMINFOFILE
#define PROCMEMINFOFILE PROCDIR "/meminfo" #define PROCMEMINFOFILE "/proc/meminfo"
#endif #endif
#ifndef MAX_NAME #ifndef MAX_NAME
@ -60,7 +60,7 @@ in the source distribution for its full text.
/*{ /*{
#ifdef DEBUG_PROC #ifdef DEBUG
typedef int(*vxscanf)(void*, const char*, va_list); typedef int(*vxscanf)(void*, const char*, va_list);
#endif #endif
@ -118,7 +118,7 @@ typedef struct ProcessList_ {
bool highlightBaseName; bool highlightBaseName;
bool highlightMegabytes; bool highlightMegabytes;
bool expandSystemTime; bool expandSystemTime;
#ifdef DEBUG_PROC #ifdef DEBUG
FILE* traceFile; FILE* traceFile;
#endif #endif
@ -127,7 +127,7 @@ typedef struct ProcessList_ {
static ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; static ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 };
#ifdef DEBUG_PROC #ifdef DEBUG
#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ ) #define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ )
#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ ) #define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ )
@ -204,14 +204,13 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
this = malloc(sizeof(ProcessList)); this = malloc(sizeof(ProcessList));
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare); this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
this->processTable = Hashtable_new(70, false); this->processTable = Hashtable_new(70, false);
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
this->prototype = Process_new(this); this->prototype = Process_new(this);
this->usersTable = usersTable; this->usersTable = usersTable;
/* tree-view auxiliary buffers */ /* tree-view auxiliary buffers */
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare); this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
#ifdef DEBUG_PROC #ifdef DEBUG
this->traceFile = fopen("/tmp/htop-proc-trace", "w"); this->traceFile = fopen("/tmp/htop-proc-trace", "w");
#endif #endif
@ -263,7 +262,7 @@ void ProcessList_delete(ProcessList* this) {
// other fields are offsets of the same buffer // other fields are offsets of the same buffer
free(this->totalTime); free(this->totalTime);
#ifdef DEBUG_PROC #ifdef DEBUG
fclose(this->traceFile); fclose(this->traceFile);
#endif #endif
@ -298,26 +297,14 @@ void ProcessList_prune(ProcessList* this) {
} }
void ProcessList_add(ProcessList* this, Process* p) { void ProcessList_add(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) == -1);
assert(Hashtable_get(this->processTable, p->pid) == NULL);
Vector_add(this->processes, p); Vector_add(this->processes, p);
Hashtable_put(this->processTable, p->pid, p); Hashtable_put(this->processTable, p->pid, p);
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
assert(Hashtable_get(this->processTable, p->pid) != NULL);
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
} }
void ProcessList_remove(ProcessList* this, Process* p) { void ProcessList_remove(ProcessList* this, Process* p) {
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); Hashtable_remove(this->processTable, p->pid);
assert(Hashtable_get(this->processTable, p->pid) != NULL);
Process* pp = Hashtable_remove(this->processTable, p->pid);
assert(pp == p); (void)pp;
unsigned int pid = p->pid;
int index = Vector_indexOf(this->processes, p, Process_pidCompare); int index = Vector_indexOf(this->processes, p, Process_pidCompare);
assert(index != -1);
Vector_remove(this->processes, index); Vector_remove(this->processes, index);
assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid;
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
} }
Process* ProcessList_get(ProcessList* this, int index) { Process* ProcessList_get(ProcessList* this, int index) {
@ -331,22 +318,21 @@ int ProcessList_size(ProcessList* this) {
static void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) { static void ProcessList_buildTree(ProcessList* this, int pid, int level, int indent, int direction) {
Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE, Process_compare); Vector* children = Vector_new(PROCESS_CLASS, false, DEFAULT_SIZE, Process_compare);
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { for (int i = 0; i < Vector_size(this->processes); i++) {
Process* process = (Process*) (Vector_get(this->processes, i)); Process* process = (Process*) (Vector_get(this->processes, i));
if (process->ppid == pid) { if (process->ppid == pid) {
Process* process = (Process*) (Vector_take(this->processes, i)); Process* process = (Process*) (Vector_take(this->processes, i));
Vector_add(children, process); Vector_add(children, process);
i--;
} }
} }
int size = Vector_size(children); int size = Vector_size(children);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Process* process = (Process*) (Vector_get(children, i)); Process* process = (Process*) (Vector_get(children, i));
int s = this->processes2->items;
if (direction == 1) if (direction == 1)
Vector_add(this->processes2, process); Vector_add(this->processes2, process);
else else
Vector_insert(this->processes2, 0, process); Vector_insert(this->processes2, 0, process);
assert(this->processes2->items == s+1); (void)s;
int nextIndent = indent; int nextIndent = indent;
if (i < size - 1) if (i < size - 1)
nextIndent = indent | (1 << level); nextIndent = indent | (1 << level);
@ -367,19 +353,11 @@ void ProcessList_sort(ProcessList* this) {
Vector_sort(this->processes); Vector_sort(this->processes);
this->sortKey = sortKey; this->sortKey = sortKey;
this->direction = direction; this->direction = direction;
int vsize = Vector_size(this->processes);
Process* init = (Process*) (Vector_take(this->processes, 0)); Process* init = (Process*) (Vector_take(this->processes, 0));
assert(init->pid == 1); assert(init->pid == 1);
init->indent = 0; init->indent = 0;
Vector_add(this->processes2, init); Vector_add(this->processes2, init);
ProcessList_buildTree(this, init->pid, 0, 0, direction); ProcessList_buildTree(this, init->pid, 0, 0, direction);
while (Vector_size(this->processes)) {
Process* p = (Process*) (Vector_take(this->processes, 0));
p->indent = 0;
Vector_add(this->processes2, p);
}
assert(Vector_size(this->processes2) == vsize); (void)vsize;
assert(Vector_size(this->processes) == 0);
Vector* t = this->processes; Vector* t = this->processes;
this->processes = this->processes2; this->processes = this->processes2;
this->processes2 = t; this->processes2 = t;
@ -393,7 +371,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
int size = fread(buf, 1, MAX_READ, f); int size = fread(buf, 1, MAX_READ, f);
if(!size) return 0; if(!size) return 0;
assert(proc->pid == atoi(buf)); proc->pid = atoi(buf);
char *location = strchr(buf, ' '); char *location = strchr(buf, ' ');
if(!location) return 0; if(!location) return 0;
@ -406,9 +384,9 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
command[commsize] = '\0'; command[commsize] = '\0';
location = end + 2; location = end + 2;
#ifdef DEBUG_PROC #ifdef DEBUG
int num = ProcessList_read(this, location, int num = ProcessList_read(this, location,
"%c %u %u %u %u %u %lu %lu %lu %lu " "%c %d %d %d %d %d %lu %lu %lu %lu "
"%lu %lu %lu %ld %ld %ld %ld %ld %ld " "%lu %lu %lu %ld %ld %ld %ld %ld %ld "
"%lu %lu %ld %lu %lu %lu %lu %lu " "%lu %lu %ld %lu %lu %lu %lu %lu "
"%lu %lu %lu %lu %lu %lu %lu %lu " "%lu %lu %lu %lu %lu %lu %lu %lu "
@ -417,7 +395,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
&proc->tpgid, &proc->flags, &proc->tpgid, &proc->flags,
&proc->minflt, &proc->cminflt, &proc->majflt, &proc->cmajflt, &proc->minflt, &proc->cminflt, &proc->majflt, &proc->cmajflt,
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime, &proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
&proc->priority, &proc->nice, &proc->nlwp, &proc->itrealvalue, &proc->priority, &proc->nice, &zero, &proc->itrealvalue,
&proc->starttime, &proc->vsize, &proc->rss, &proc->rlim, &proc->starttime, &proc->vsize, &proc->rss, &proc->rlim,
&proc->startcode, &proc->endcode, &proc->startstack, &proc->kstkesp, &proc->startcode, &proc->endcode, &proc->startstack, &proc->kstkesp,
&proc->kstkeip, &proc->signal, &proc->blocked, &proc->sigignore, &proc->kstkeip, &proc->signal, &proc->blocked, &proc->sigignore,
@ -426,7 +404,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
#else #else
long int uzero; long int uzero;
int num = ProcessList_read(this, location, int num = ProcessList_read(this, location,
"%c %u %u %u %u %u %lu %lu %lu %lu " "%c %d %d %d %d %d %lu %lu %lu %lu "
"%lu %lu %lu %ld %ld %ld %ld %ld %ld " "%lu %lu %lu %ld %ld %ld %ld %ld %ld "
"%lu %lu %ld %lu %lu %lu %lu %lu " "%lu %lu %ld %lu %lu %lu %lu %lu "
"%lu %lu %lu %lu %lu %lu %lu %lu " "%lu %lu %lu %lu %lu %lu %lu %lu "
@ -435,7 +413,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
&proc->tpgid, &proc->flags, &proc->tpgid, &proc->flags,
&zero, &zero, &zero, &zero, &zero, &zero, &zero, &zero,
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime, &proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
&proc->priority, &proc->nice, &proc->nlwp, &uzero, &proc->priority, &proc->nice, &uzero, &uzero,
&zero, &zero, &uzero, &zero, &zero, &zero, &uzero, &zero,
&zero, &zero, &zero, &zero, &zero, &zero, &zero, &zero,
&zero, &zero, &zero, &zero, &zero, &zero, &zero, &zero,
@ -499,7 +477,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
Process* prototype = this->prototype; Process* prototype = this->prototype;
dir = opendir(dirname); dir = opendir(dirname);
if (!dir) return; assert(dir != NULL);
while ((entry = readdir(dir)) != NULL) { while ((entry = readdir(dir)) != NULL) {
char* name = entry->d_name; char* name = entry->d_name;
int pid; int pid;
@ -530,17 +508,14 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
char statusfilename[MAX_NAME+1]; char statusfilename[MAX_NAME+1];
char command[PROCESS_COMM_LEN + 1]; char command[PROCESS_COMM_LEN + 1];
Process* process = NULL; Process* process;
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid); Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid);
if (existingProcess) { if (existingProcess) {
assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1);
process = existingProcess; process = existingProcess;
assert(process->pid == pid);
} else { } else {
process = prototype; process = prototype;
assert(process->comm == NULL); process->comm = NULL;
process->pid = pid; process->pid = pid;
if (! ProcessList_readStatusFile(this, process, dirname, name)) if (! ProcessList_readStatusFile(this, process, dirname, name))
goto errorReadingProcess; goto errorReadingProcess;
@ -555,7 +530,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
} }
int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d", int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d",
&process->m_size, &process->m_resident, &process->m_share, &process->m_size, &process->m_resident, &process->m_share,
&process->m_trs, &process->m_lrs, &process->m_drs, &process->m_trs, &process->m_drs, &process->m_lrs,
&process->m_dt); &process->m_dt);
fclose(status); fclose(status);
@ -602,8 +577,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
process->percent_cpu = (process->utime + process->stime - lasttimes) / process->percent_cpu = (process->utime + process->stime - lasttimes) /
period * 100.0; period * 100.0;
process->percent_mem = (process->m_resident * PAGE_SIZE) / process->percent_mem = process->m_resident /
(float)(this->totalMem) * (float)(this->usedMem - this->cachedMem - this->buffersMem) *
100.0; 100.0;
this->totalTasks++; this->totalTasks++;
@ -612,23 +587,24 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
} }
if (!existingProcess) { if (!existingProcess) {
ProcessList_add(this, Process_clone(process)); process = Process_clone(process);
ProcessList_add(this, process);
} }
continue; continue;
// Exception handler. // Exception handler.
errorReadingProcess: { errorReadingProcess: {
if (process->comm) {
free(process->comm);
process->comm = NULL;
}
if (existingProcess) if (existingProcess)
ProcessList_remove(this, process); ProcessList_remove(this, process);
assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); else {
if (process->comm)
free(process->comm);
}
} }
} }
} }
prototype->comm = NULL;
closedir(dir); closedir(dir);
} }

View File

@ -39,11 +39,11 @@ in the source distribution for its full text.
#endif #endif
#ifndef PROCSTATFILE #ifndef PROCSTATFILE
#define PROCSTATFILE PROCDIR "/stat" #define PROCSTATFILE "/proc/stat"
#endif #endif
#ifndef PROCMEMINFOFILE #ifndef PROCMEMINFOFILE
#define PROCMEMINFOFILE PROCDIR "/meminfo" #define PROCMEMINFOFILE "/proc/meminfo"
#endif #endif
#ifndef MAX_NAME #ifndef MAX_NAME
@ -60,7 +60,7 @@ in the source distribution for its full text.
#ifdef DEBUG_PROC #ifdef DEBUG
typedef int(*vxscanf)(void*, const char*, va_list); typedef int(*vxscanf)(void*, const char*, va_list);
#endif #endif
@ -118,13 +118,13 @@ typedef struct ProcessList_ {
bool highlightBaseName; bool highlightBaseName;
bool highlightMegabytes; bool highlightMegabytes;
bool expandSystemTime; bool expandSystemTime;
#ifdef DEBUG_PROC #ifdef DEBUG
FILE* traceFile; FILE* traceFile;
#endif #endif
} ProcessList; } ProcessList;
#ifdef DEBUG_PROC #ifdef DEBUG
#define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ ) #define ProcessList_read(this, buffer, format, ...) ProcessList_xread(this, (vxscanf) vsscanf, buffer, format, ## __VA_ARGS__ )
#define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ ) #define ProcessList_fread(this, file, format, ...) ProcessList_xread(this, (vxscanf) vfscanf, file, format, ## __VA_ARGS__ )

View File

@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) {
free(this); free(this);
} }
char* UsersTable_getRef(UsersTable* this, unsigned int uid) { char* UsersTable_getRef(UsersTable* this, int uid) {
char* name = (char*) (Hashtable_get(this->users, uid)); char* name = (char*) (Hashtable_get(this->users, uid));
if (name == NULL) { if (name == NULL) {
struct passwd* userData = getpwuid(uid); struct passwd* userData = getpwuid(uid);

View File

@ -28,7 +28,7 @@ UsersTable* UsersTable_new();
void UsersTable_delete(UsersTable* this); void UsersTable_delete(UsersTable* this);
char* UsersTable_getRef(UsersTable* this, unsigned int uid); char* UsersTable_getRef(UsersTable* this, int uid);
inline int UsersTable_size(UsersTable* this); inline int UsersTable_size(UsersTable* this);

View File

@ -63,7 +63,6 @@ void Vector_delete(Vector* this) {
#ifdef DEBUG #ifdef DEBUG
static inline bool Vector_isConsistent(Vector* this) { static inline bool Vector_isConsistent(Vector* this) {
assert(this->items <= this->arraySize);
if (this->owner) { if (this->owner) {
for (int i = 0; i < this->items; i++) for (int i = 0; i < this->items; i++)
if (this->array[i] && this->array[i]->class != this->vectorType) if (this->array[i] && this->array[i]->class != this->vectorType)
@ -74,16 +73,6 @@ static inline bool Vector_isConsistent(Vector* this) {
} }
} }
int Vector_count(Vector* this) {
int items = 0;
for (int i = 0; i < this->items; i++) {
if (this->array[i])
items++;
}
assert(items == this->items);
return items;
}
#endif #endif
void Vector_prune(Vector* this) { void Vector_prune(Vector* this) {
@ -233,9 +222,8 @@ void Vector_add(Vector* this, void* data_) {
assert(data_ && ((Object*)data_)->class == this->vectorType); assert(data_ && ((Object*)data_)->class == this->vectorType);
Object* data = data_; Object* data = data_;
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
int i = this->items;
Vector_set(this, this->items, data); Vector_set(this, this->items, data);
assert(this->items == i+1); (void)(i);
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
} }

View File

@ -41,8 +41,6 @@ void Vector_delete(Vector* this);
#ifdef DEBUG #ifdef DEBUG
int Vector_count(Vector* this);
#endif #endif
void Vector_prune(Vector* this); void Vector_prune(Vector* this);

View File

@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57) AC_PREREQ(2.57)
AC_INIT([htop],[0.6.6],[loderunner@users.sourceforge.net]) AC_INIT([htop],[0.6.4],[loderunner@users.sourceforge.net])
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([htop.c]) AC_CONFIG_SRCDIR([htop.c])
AC_CONFIG_HEADER([config.h]) AC_CONFIG_HEADER([config.h])
@ -15,7 +15,7 @@ AC_CHECK_LIB([ncurses], [refresh], [], [missing_libraries="$missing_libraries li
AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"]) AC_CHECK_LIB([m], [ceil], [], [missing_libraries="$missing_libraries libm"])
if test ! -z "$missing_libraries"; then if test ! -z "$missing_libraries"; then
AC_MSG_ERROR([missing libraries: $missing_libraries]) AC_MSG_ERROR([missing libraries:$missing_headers])
fi fi
# Checks for header files. # Checks for header files.
@ -26,7 +26,7 @@ AC_CHECK_HEADERS([stdlib.h string.h strings.h sys/param.h sys/time.h unistd.h cu
]) ])
if test ! -z "$missing_headers"; then if test ! -z "$missing_headers"; then
AC_MSG_ERROR([missing headers: $missing_headers]) AC_MSG_ERROR([missing headers:$missing_headers])
fi fi
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.

2
htop.1
View File

@ -1,4 +1,4 @@
.TH "htop" "1" "0.6.6" "Bartosz Fenski <fenio@o2.pl>" "Utils" .TH "htop" "1" "0.6.4" "Bartosz Fenski <fenio@o2.pl>" "Utils"
.SH "NAME" .SH "NAME"
htop \- interactive process viewer htop \- interactive process viewer
.SH "SYNTAX" .SH "SYNTAX"

57
htop.c
View File

@ -93,36 +93,35 @@ void showHelp(ProcessList* pl) {
addattrstr(CRT_colors[BAR_BORDER], "]"); addattrstr(CRT_colors[BAR_BORDER], "]");
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
mvaddstr(6,0, "Type and layout of header meters are configurable in the setup screen."); mvaddstr(6,0, "Type and layout of header meters are configurable in the setup screen.");
mvaddstr(7, 0, "Status: R: running; S: sleeping; T: traced/stopped; Z: zombie; D: disk sleep");
mvaddstr( 9, 0, " Arrows: scroll process list F5 t: tree view"); mvaddstr( 8, 0, " Arrows: scroll process list F5 t: tree view");
mvaddstr(10, 0, " Digits: incremental PID search u: show processes of a single user"); mvaddstr( 9, 0, " Digits: incremental PID search u: show processes of a single user");
mvaddstr(11, 0, " F3 /: incremental name search H: hide/show user threads"); mvaddstr(10, 0, " F3 /: incremental name search H: hide/show user threads");
mvaddstr(12, 0, " K: hide/show kernel threads"); mvaddstr(11, 0, " K: hide/show kernel threads");
mvaddstr(13, 0, " Space: tag processes F: cursor follows process"); mvaddstr(12, 0, " Space: tag processes F: cursor follows process");
mvaddstr(14, 0, " U: untag all processes"); mvaddstr(13, 0, " U: untag all processes");
mvaddstr(15, 0, " F9 k: kill process/tagged processes P: sort by CPU%"); mvaddstr(14, 0, " F9 k: kill process/tagged processes P: sort by CPU%");
mvaddstr(16, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%"); mvaddstr(15, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%");
mvaddstr(17, 0, " - ] F8: higher priority (root only) T: sort by TIME"); mvaddstr(16, 0, " - ] F8: higher priority (root only) T: sort by TIME");
mvaddstr(18, 0, " F4 I: invert sort order"); mvaddstr(17, 0, " F4 I: invert sort order");
mvaddstr(19, 0, " F2 S: setup F6 >: select sort column"); mvaddstr(18, 0, " F2 S: setup F6 >: select sort column");
mvaddstr(20, 0, " F1 h: show this help screen"); mvaddstr(19, 0, " F1 h: show this help screen");
mvaddstr(21, 0, " F10 q: quit s: trace syscalls with strace"); mvaddstr(20, 0, " F10 q: quit s: trace syscalls with strace");
attrset(CRT_colors[HELP_BOLD]); attrset(CRT_colors[HELP_BOLD]);
mvaddstr( 9, 0, " Arrows"); mvaddstr( 9,40, " F5 t"); mvaddstr( 8, 0, " Arrows"); mvaddstr( 8,40, " F5 t");
mvaddstr(10, 0, " Digits"); mvaddstr(10,40, " u"); mvaddstr( 9, 0, " Digits"); mvaddstr( 9,40, " u");
mvaddstr(11, 0, " F3 /"); mvaddstr(11,40, " H"); mvaddstr(10, 0, " F3 /"); mvaddstr(10,40, " H");
mvaddstr(12,40, " K"); mvaddstr(11,40, " K");
mvaddstr(13, 0, " Space"); mvaddstr(13,40, " F"); mvaddstr(12, 0, " Space"); mvaddstr(12,40, " F");
mvaddstr(14, 0, " U"); mvaddstr(13, 0, " U");
mvaddstr(15, 0, " F9 k"); mvaddstr(15,40, " P"); mvaddstr(14, 0, " F9 k"); mvaddstr(14,40, " P");
mvaddstr(16, 0, " + [ F7"); mvaddstr(16,40, " M"); mvaddstr(15, 0, " + [ F7"); mvaddstr(15,40, " M");
mvaddstr(17, 0, " - ] F8"); mvaddstr(17,40, " T"); mvaddstr(16, 0, " - ] F8"); mvaddstr(16,40, " T");
mvaddstr(18,40, " F4 I"); mvaddstr(17,40, " F4 I");
mvaddstr(19, 0, " F2 S"); mvaddstr(19,40, " F6 >"); mvaddstr(18, 0, " F2 S"); mvaddstr(18,40, " F6 >");
mvaddstr(20, 0, " F1 h"); mvaddstr(19, 0, " F1 h");
mvaddstr(21, 0, " F10 q"); mvaddstr(21,40, " s"); mvaddstr(20, 0, " F10 q"); mvaddstr(20,40, " s");
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
attrset(CRT_colors[HELP_BOLD]); attrset(CRT_colors[HELP_BOLD]);
@ -312,7 +311,7 @@ int main(int argc, char** argv) {
incSearchIndex = 0; incSearchIndex = 0;
incSearchBuffer[0] = 0; incSearchBuffer[0] = 0;
int currPos = Panel_getSelectedIndex(panel); int currPos = Panel_getSelectedIndex(panel);
unsigned int currPid = 0; int currPid = 0;
int currScrollV = panel->scrollV; int currScrollV = panel->scrollV;
if (follow) if (follow)
currPid = ProcessList_get(pl, currPos)->pid; currPid = ProcessList_get(pl, currPos)->pid;
@ -406,7 +405,7 @@ int main(int argc, char** argv) {
continue; continue;
} }
if (isdigit((char)ch)) { if (isdigit((char)ch)) {
unsigned int pid = ch-48 + acc; int pid = ch-48 + acc;
for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++) for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++)
Panel_setSelected(panel, i); Panel_setSelected(panel, i);
acc = pid * 10; acc = pid * 10;

View File

@ -1,6 +1,6 @@
[Desktop Entry] [Desktop Entry]
Encoding=UTF-8 Encoding=UTF-8
Version=0.6.6 Version=0.6.4
Name=Htop Name=Htop
Type=Application Type=Application
Comment=Show System Processes Comment=Show System Processes

View File

@ -21,8 +21,6 @@ class writer:
self.file.write(text + "\n") self.file.write(text + "\n")
out = writer(out) out = writer(out)
print("Generating "+name+".h")
selfheader = '#include "' + name + '.h"' selfheader = '#include "' + name + '.h"'
out.write( "/* Do not edit this file. It was automatically generated. */" ) out.write( "/* Do not edit this file. It was automatically generated. */" )