mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-15 05:24:36 +03:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
3d891c3851 | |||
d357c67717 | |||
e1a7e2bdef | |||
d2f767e607 | |||
b1e9d716f2 | |||
6271138237 | |||
255c62a460 | |||
9710a43001 | |||
df20abfd67 | |||
d46dcf99fd | |||
f56c8014f7 | |||
a227b20fef | |||
e3198ca63b | |||
92a5a691fd | |||
6b6b4373b5 | |||
2a025bf4c6 | |||
14808f7f70 | |||
a26ef71ed8 | |||
a8f45d5743 | |||
9076b9edeb | |||
0f027ded2c | |||
3d62edb678 | |||
36848494f5 | |||
c90a445103 | |||
97ea7a1a8c | |||
adbfe82e63 | |||
45fab61da3 | |||
8adc7ac00f | |||
2713119249 | |||
59c3dd806b | |||
c494308b21 | |||
c4fbd7fc8b | |||
febe259e91 | |||
110ce71b9b | |||
46b35b2c7f | |||
b25ac6b0f7 |
30
ChangeLog
30
ChangeLog
@ -1,3 +1,33 @@
|
||||
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
|
||||
|
||||
|
@ -49,7 +49,11 @@ void DebugMemory_new() {
|
||||
singleton->allocations = 0;
|
||||
singleton->deallocations = 0;
|
||||
singleton->size = 0;
|
||||
#ifdef DEBUG_ALLOC
|
||||
singleton->file = fopen("/tmp/htop-debug-alloc.txt", "w");
|
||||
#else
|
||||
singleton->file = NULL;
|
||||
#endif
|
||||
singleton->totals = true;
|
||||
//singleton->file = NULL;
|
||||
}
|
||||
|
91
Hashtable.c
91
Hashtable.c
@ -9,6 +9,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
@ -18,7 +19,7 @@ typedef struct Hashtable_ Hashtable;
|
||||
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
||||
|
||||
typedef struct HashtableItem {
|
||||
int key;
|
||||
unsigned int key;
|
||||
void* value;
|
||||
struct HashtableItem* next;
|
||||
} HashtableItem;
|
||||
@ -31,7 +32,36 @@ struct Hashtable_ {
|
||||
};
|
||||
}*/
|
||||
|
||||
HashtableItem* HashtableItem_new(int key, void* value) {
|
||||
#ifdef DEBUG
|
||||
|
||||
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;
|
||||
|
||||
this = (HashtableItem*) malloc(sizeof(HashtableItem));
|
||||
@ -45,13 +75,16 @@ Hashtable* Hashtable_new(int size, bool owner) {
|
||||
Hashtable* this;
|
||||
|
||||
this = (Hashtable*) malloc(sizeof(Hashtable));
|
||||
this->items = 0;
|
||||
this->size = size;
|
||||
this->buckets = (HashtableItem**) calloc(sizeof(HashtableItem*), size);
|
||||
this->owner = owner;
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return this;
|
||||
}
|
||||
|
||||
void Hashtable_delete(Hashtable* this) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
HashtableItem* walk = this->buckets[i];
|
||||
while (walk != NULL) {
|
||||
@ -67,11 +100,12 @@ void Hashtable_delete(Hashtable* this) {
|
||||
}
|
||||
|
||||
inline int Hashtable_size(Hashtable* this) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return this->items;
|
||||
}
|
||||
|
||||
void Hashtable_put(Hashtable* this, int key, void* value) {
|
||||
int index = key % this->size;
|
||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value) {
|
||||
unsigned int index = key % this->size;
|
||||
HashtableItem** bucketPtr = &(this->buckets[index]);
|
||||
while (true)
|
||||
if (*bucketPtr == NULL) {
|
||||
@ -85,47 +119,53 @@ void Hashtable_put(Hashtable* this, int key, void* value) {
|
||||
break;
|
||||
} else
|
||||
bucketPtr = &((*bucketPtr)->next);
|
||||
assert(Hashtable_isConsistent(this));
|
||||
}
|
||||
|
||||
void* Hashtable_remove(Hashtable* this, int key) {
|
||||
int index = key % this->size;
|
||||
HashtableItem** bucketPtr = &(this->buckets[index]);
|
||||
while (true)
|
||||
if (*bucketPtr == NULL) {
|
||||
return NULL;
|
||||
break;
|
||||
} else if ((*bucketPtr)->key == key) {
|
||||
void* savedValue = (*bucketPtr)->value;
|
||||
HashtableItem* savedNext = (*bucketPtr)->next;
|
||||
free(*bucketPtr);
|
||||
(*bucketPtr) = savedNext;
|
||||
void* Hashtable_remove(Hashtable* this, unsigned int key) {
|
||||
unsigned int index = key % this->size;
|
||||
|
||||
assert(Hashtable_isConsistent(this));
|
||||
|
||||
HashtableItem** bucket;
|
||||
for (bucket = &(this->buckets[index]); *bucket; bucket = &((*bucket)->next) ) {
|
||||
if ((*bucket)->key == key) {
|
||||
void* value = (*bucket)->value;
|
||||
HashtableItem* next = (*bucket)->next;
|
||||
free(*bucket);
|
||||
(*bucket) = next;
|
||||
this->items--;
|
||||
if (this->owner) {
|
||||
free(savedValue);
|
||||
free(value);
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return NULL;
|
||||
} else {
|
||||
return savedValue;
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return value;
|
||||
}
|
||||
} else
|
||||
bucketPtr = &((*bucketPtr)->next);
|
||||
}
|
||||
}
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return NULL;
|
||||
}
|
||||
//#include <stdio.h>
|
||||
inline void* Hashtable_get(Hashtable* this, int key) {
|
||||
int index = key % this->size;
|
||||
|
||||
inline void* Hashtable_get(Hashtable* this, unsigned int key) {
|
||||
unsigned int index = key % this->size;
|
||||
HashtableItem* bucketPtr = this->buckets[index];
|
||||
// fprintf(stderr, "%d -> %d\n", key, index);
|
||||
while (true) {
|
||||
if (bucketPtr == NULL) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return NULL;
|
||||
} else if (bucketPtr->key == key) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
return bucketPtr->value;
|
||||
} else
|
||||
bucketPtr = bucketPtr->next;
|
||||
// fprintf(stderr, "*\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData) {
|
||||
assert(Hashtable_isConsistent(this));
|
||||
for (int i = 0; i < this->size; i++) {
|
||||
HashtableItem* walk = this->buckets[i];
|
||||
while (walk != NULL) {
|
||||
@ -133,4 +173,5 @@ void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData
|
||||
walk = walk->next;
|
||||
}
|
||||
}
|
||||
assert(Hashtable_isConsistent(this));
|
||||
}
|
||||
|
21
Hashtable.h
21
Hashtable.h
@ -12,6 +12,7 @@ in the source distribution for its full text.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
@ -20,7 +21,7 @@ typedef struct Hashtable_ Hashtable;
|
||||
typedef void(*Hashtable_PairFunction)(int, void*, void*);
|
||||
|
||||
typedef struct HashtableItem {
|
||||
int key;
|
||||
unsigned int key;
|
||||
void* value;
|
||||
struct HashtableItem* next;
|
||||
} HashtableItem;
|
||||
@ -32,7 +33,15 @@ struct Hashtable_ {
|
||||
bool owner;
|
||||
};
|
||||
|
||||
HashtableItem* HashtableItem_new(int key, void* value);
|
||||
#ifdef DEBUG
|
||||
|
||||
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);
|
||||
|
||||
@ -40,11 +49,11 @@ void Hashtable_delete(Hashtable* this);
|
||||
|
||||
inline int Hashtable_size(Hashtable* this);
|
||||
|
||||
void Hashtable_put(Hashtable* this, int key, void* value);
|
||||
void Hashtable_put(Hashtable* this, unsigned int key, void* value);
|
||||
|
||||
void* Hashtable_remove(Hashtable* this, int key);
|
||||
//#include <stdio.h>
|
||||
inline void* Hashtable_get(Hashtable* this, int key);
|
||||
void* Hashtable_remove(Hashtable* this, unsigned int key);
|
||||
|
||||
inline void* Hashtable_get(Hashtable* this, unsigned int key);
|
||||
|
||||
void Hashtable_foreach(Hashtable* this, Hashtable_PairFunction f, void* userData);
|
||||
|
||||
|
50
Makefile.am
50
Makefile.am
@ -11,28 +11,42 @@ pixmap_DATA = htop.png
|
||||
AM_CFLAGS = -pedantic -Wall -std=c99
|
||||
AM_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\"
|
||||
|
||||
htop_SOURCES = AvailableMetersPanel.c CategoriesPanel.c ClockMeter.c \
|
||||
CPUMeter.c CRT.c DebugMemory.c DisplayOptionsPanel.c FunctionBar.c \
|
||||
Hashtable.c Header.c htop.c Panel.c ListItem.c LoadAverageMeter.c \
|
||||
MemoryMeter.c Meter.c MetersPanel.c Object.c Process.c \
|
||||
ProcessList.c RichString.c ScreenManager.c Settings.c SignalItem.c \
|
||||
SignalsPanel.c String.c SwapMeter.c TasksMeter.c Vector.c \
|
||||
UptimeMeter.c UsersTable.c AvailableMetersPanel.h CategoriesPanel.h \
|
||||
ClockMeter.h config.h CPUMeter.h CRT.h debug.h DebugMemory.h \
|
||||
DisplayOptionsPanel.h FunctionBar.h Hashtable.h Header.h htop.h Panel.h \
|
||||
ListItem.h LoadAverageMeter.h MemoryMeter.h Meter.h \
|
||||
MetersPanel.h Object.h Process.h ProcessList.h RichString.h ScreenManager.h \
|
||||
Settings.h SignalItem.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
|
||||
Vector.h UptimeMeter.h UsersTable.h CheckItem.c CheckItem.h \
|
||||
ColorsPanel.c ColorsPanel.h TraceScreen.c TraceScreen.h \
|
||||
AvailableColumnsPanel.c AvailableColumnsPanel.h ColumnsPanel.c \
|
||||
ColumnsPanel.h
|
||||
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
|
||||
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c DebugMemory.c \
|
||||
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
|
||||
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
|
||||
Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
|
||||
SignalItem.c SignalsPanel.c String.c SwapMeter.c TasksMeter.c TraceScreen.c \
|
||||
UptimeMeter.c UsersTable.c Vector.c AvailableColumnsPanel.c
|
||||
|
||||
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
|
||||
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
|
||||
CPUMeter.h CRT.h DebugMemory.h DisplayOptionsPanel.h FunctionBar.h \
|
||||
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
|
||||
Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
|
||||
ScreenManager.h Settings.h SignalItem.h SignalsPanel.h String.h \
|
||||
SwapMeter.h TasksMeter.h TraceScreen.h UptimeMeter.h UsersTable.h Vector.h \
|
||||
Process.h
|
||||
|
||||
SUFFIXES = .h
|
||||
|
||||
BUILT_SOURCES = $(myhtopheaders)
|
||||
htop_SOURCES = $(myhtopheaders) $(myhtopsources) config.h debug.h
|
||||
|
||||
profile:
|
||||
$(MAKE) all CFLAGS="-pg -O2"
|
||||
|
||||
debug:
|
||||
$(MAKE) all CFLAGS="-g -DDEBUG"
|
||||
$(MAKE) all CFLAGS="-ggdb -DDEBUG"
|
||||
|
||||
hardened-debug:
|
||||
$(MAKE) all CFLAGS="-ggdb -DDEBUG" LDFLAGS="-nopie"
|
||||
|
||||
debuglite:
|
||||
$(MAKE) all CFLAGS="-g -DDEBUGLITE"
|
||||
$(MAKE) all CFLAGS="-ggdb -DDEBUGLITE"
|
||||
|
||||
.c.h:
|
||||
scripts/MakeHeader.py $<
|
||||
|
||||
|
||||
|
||||
|
67
Process.c
67
Process.c
@ -28,7 +28,9 @@ in the source distribution for its full text.
|
||||
|
||||
// This works only with glibc 2.1+. On earlier versions
|
||||
// the behavior is similar to have a hardcoded page size.
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
||||
#endif
|
||||
|
||||
#define PROCESS_COMM_LEN 300
|
||||
|
||||
@ -39,7 +41,7 @@ typedef enum ProcessField_ {
|
||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||
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,
|
||||
USER, TIME, LAST_PROCESSFIELD
|
||||
USER, TIME, NLWP, LAST_PROCESSFIELD
|
||||
} ProcessField;
|
||||
|
||||
struct ProcessList_;
|
||||
@ -50,16 +52,16 @@ typedef struct Process_ {
|
||||
struct ProcessList_ *pl;
|
||||
bool updated;
|
||||
|
||||
int pid;
|
||||
unsigned int pid;
|
||||
char* comm;
|
||||
int indent;
|
||||
char state;
|
||||
bool tag;
|
||||
int ppid;
|
||||
int pgrp;
|
||||
int session;
|
||||
int tty_nr;
|
||||
int tpgid;
|
||||
unsigned int ppid;
|
||||
unsigned int pgrp;
|
||||
unsigned int session;
|
||||
unsigned int tty_nr;
|
||||
unsigned int tpgid;
|
||||
unsigned long int flags;
|
||||
#ifdef DEBUG
|
||||
unsigned long int minflt;
|
||||
@ -73,6 +75,7 @@ typedef struct Process_ {
|
||||
long int cstime;
|
||||
long int priority;
|
||||
long int nice;
|
||||
long int nlwp;
|
||||
#ifdef DEBUG
|
||||
long int itrealvalue;
|
||||
unsigned long int starttime;
|
||||
@ -116,7 +119,7 @@ char* PROCESS_CLASS = "Process";
|
||||
#endif
|
||||
|
||||
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", "*** 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", "NLWP", "*** report bug! ***"
|
||||
};
|
||||
|
||||
static int Process_getuid = -1;
|
||||
@ -126,12 +129,14 @@ Process* Process_new(struct ProcessList_ *pl) {
|
||||
Object_setClass(this, PROCESS_CLASS);
|
||||
((Object*)this)->display = Process_display;
|
||||
((Object*)this)->delete = Process_delete;
|
||||
this->pid = 0;
|
||||
this->pl = pl;
|
||||
this->tag = false;
|
||||
this->updated = false;
|
||||
this->utime = 0;
|
||||
this->stime = 0;
|
||||
this->comm = NULL;
|
||||
this->indent = 0;
|
||||
if (Process_getuid == -1) Process_getuid = getuid();
|
||||
return this;
|
||||
}
|
||||
@ -139,13 +144,15 @@ Process* Process_new(struct ProcessList_ *pl) {
|
||||
Process* Process_clone(Process* this) {
|
||||
Process* clone = malloc(sizeof(Process));
|
||||
memcpy(clone, this, sizeof(Process));
|
||||
this->comm = NULL;
|
||||
this->pid = 0;
|
||||
return clone;
|
||||
}
|
||||
|
||||
void Process_delete(Object* cast) {
|
||||
Process* this = (Process*) cast;
|
||||
if (this->comm) free(this->comm);
|
||||
assert (this != NULL);
|
||||
if (this->comm) free(this->comm);
|
||||
free(this);
|
||||
}
|
||||
|
||||
@ -182,26 +189,26 @@ void Process_sendSignal(Process* this, int signal) {
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
#define ONE_G (ONE_M * ONE_K)
|
||||
|
||||
static void Process_printLargeNumber(Process* this, RichString *str, unsigned int number) {
|
||||
static void Process_printLargeNumber(Process* this, RichString *str, unsigned long number) {
|
||||
char buffer[11];
|
||||
int len;
|
||||
if(number >= (1000 * ONE_M)) {
|
||||
len = snprintf(buffer, 10, "%4.2fG ", (float)number / ONE_M);
|
||||
RichString_appendn(str, CRT_colors[LARGE_NUMBER], buffer, len);
|
||||
} else if(number >= (100000)) {
|
||||
len = snprintf(buffer, 10, "%4dM ", number / ONE_K);
|
||||
len = snprintf(buffer, 10, "%4ldM ", number / ONE_K);
|
||||
int attr = this->pl->highlightMegabytes
|
||||
? CRT_colors[PROCESS_MEGABYTES]
|
||||
: CRT_colors[PROCESS];
|
||||
RichString_appendn(str, attr, buffer, len);
|
||||
} else if (this->pl->highlightMegabytes && number >= 1000) {
|
||||
len = snprintf(buffer, 10, "%2d", number/1000);
|
||||
len = snprintf(buffer, 10, "%2ld", number/1000);
|
||||
RichString_appendn(str, CRT_colors[PROCESS_MEGABYTES], buffer, len);
|
||||
number %= 1000;
|
||||
len = snprintf(buffer, 10, "%03d ", number);
|
||||
len = snprintf(buffer, 10, "%03ld ", number);
|
||||
RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
|
||||
} else {
|
||||
len = snprintf(buffer, 10, "%5d ", number);
|
||||
len = snprintf(buffer, 10, "%5ld ", number);
|
||||
RichString_appendn(str, CRT_colors[PROCESS], buffer, len);
|
||||
}
|
||||
}
|
||||
@ -257,13 +264,14 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
int n = PROCESS_COMM_LEN;
|
||||
|
||||
switch (field) {
|
||||
case PID: snprintf(buffer, n, "%5d ", this->pid); break;
|
||||
case PPID: snprintf(buffer, n, "%5d ", this->ppid); break;
|
||||
case PGRP: snprintf(buffer, n, "%5d ", this->pgrp); break;
|
||||
case SESSION: snprintf(buffer, n, "%5d ", this->session); break;
|
||||
case TTY_NR: snprintf(buffer, n, "%5d ", this->tty_nr); break;
|
||||
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
|
||||
case PID: snprintf(buffer, n, "%5u ", this->pid); break;
|
||||
case PPID: snprintf(buffer, n, "%5u ", this->ppid); break;
|
||||
case PGRP: snprintf(buffer, n, "%5u ", this->pgrp); break;
|
||||
case SESSION: snprintf(buffer, n, "%5u ", this->session); break;
|
||||
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
||||
case TPGID: snprintf(buffer, n, "%5u ", this->tpgid); break;
|
||||
case PROCESSOR: snprintf(buffer, n, "%3d ", this->processor+1); break;
|
||||
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
|
||||
case COMM: {
|
||||
if (!this->pl->treeView || this->indent == 0) {
|
||||
Process_writeCommand(this, attr, str);
|
||||
@ -312,6 +320,10 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||
: attr;
|
||||
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_RESIDENT: Process_printLargeNumber(this, str, this->m_resident * PAGE_SIZE); return;
|
||||
case M_SHARE: Process_printLargeNumber(this, str, this->m_share * PAGE_SIZE); return;
|
||||
@ -387,6 +399,14 @@ int Process_compare(const void* v1, const void* v2) {
|
||||
return (p1->state - p2->state);
|
||||
case 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:
|
||||
return (p2->m_size - p1->m_size);
|
||||
case M_RESIDENT:
|
||||
@ -405,6 +425,8 @@ int Process_compare(const void* v1, const void* v2) {
|
||||
return ((p2->utime+p2->stime) - (p1->utime+p1->stime));
|
||||
case COMM:
|
||||
return strcmp(p1->comm, p2->comm);
|
||||
case NLWP:
|
||||
return (p1->nlwp - p2->nlwp);
|
||||
default:
|
||||
return (p1->pid - p2->pid);
|
||||
}
|
||||
@ -423,6 +445,10 @@ char* Process_printField(ProcessField field) {
|
||||
case STATE: return "S ";
|
||||
case PRIORITY: return "PRI ";
|
||||
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_RESIDENT: return " RES ";
|
||||
case M_SHARE: return " SHR ";
|
||||
@ -434,6 +460,7 @@ char* Process_printField(ProcessField field) {
|
||||
case PERCENT_CPU: return "CPU% ";
|
||||
case PERCENT_MEM: return "MEM% ";
|
||||
case PROCESSOR: return "CPU ";
|
||||
case NLWP: return "NLWP ";
|
||||
default: return "- ";
|
||||
}
|
||||
}
|
||||
|
17
Process.h
17
Process.h
@ -31,7 +31,9 @@ in the source distribution for its full text.
|
||||
|
||||
// This works only with glibc 2.1+. On earlier versions
|
||||
// the behavior is similar to have a hardcoded page size.
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE ( sysconf(_SC_PAGESIZE) / 1024 )
|
||||
#endif
|
||||
|
||||
#define PROCESS_COMM_LEN 300
|
||||
|
||||
@ -41,7 +43,7 @@ typedef enum ProcessField_ {
|
||||
STIME, CUTIME, CSTIME, PRIORITY, NICE, ITREALVALUE, STARTTIME, VSIZE, RSS, RLIM, STARTCODE, ENDCODE,
|
||||
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,
|
||||
USER, TIME, LAST_PROCESSFIELD
|
||||
USER, TIME, NLWP, LAST_PROCESSFIELD
|
||||
} ProcessField;
|
||||
|
||||
struct ProcessList_;
|
||||
@ -52,16 +54,16 @@ typedef struct Process_ {
|
||||
struct ProcessList_ *pl;
|
||||
bool updated;
|
||||
|
||||
int pid;
|
||||
unsigned int pid;
|
||||
char* comm;
|
||||
int indent;
|
||||
char state;
|
||||
bool tag;
|
||||
int ppid;
|
||||
int pgrp;
|
||||
int session;
|
||||
int tty_nr;
|
||||
int tpgid;
|
||||
unsigned int ppid;
|
||||
unsigned int pgrp;
|
||||
unsigned int session;
|
||||
unsigned int tty_nr;
|
||||
unsigned int tpgid;
|
||||
unsigned long int flags;
|
||||
#ifdef DEBUG
|
||||
unsigned long int minflt;
|
||||
@ -75,6 +77,7 @@ typedef struct Process_ {
|
||||
long int cstime;
|
||||
long int priority;
|
||||
long int nice;
|
||||
long int nlwp;
|
||||
#ifdef DEBUG
|
||||
long int itrealvalue;
|
||||
unsigned long int starttime;
|
||||
|
@ -37,11 +37,11 @@ in the source distribution for its full text.
|
||||
#endif
|
||||
|
||||
#ifndef PROCSTATFILE
|
||||
#define PROCSTATFILE "/proc/stat"
|
||||
#define PROCSTATFILE PROCDIR "/stat"
|
||||
#endif
|
||||
|
||||
#ifndef PROCMEMINFOFILE
|
||||
#define PROCMEMINFOFILE "/proc/meminfo"
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
@ -60,7 +60,7 @@ in the source distribution for its full text.
|
||||
|
||||
/*{
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
typedef int(*vxscanf)(void*, const char*, va_list);
|
||||
#endif
|
||||
|
||||
@ -118,7 +118,7 @@ typedef struct ProcessList_ {
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool expandSystemTime;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
FILE* traceFile;
|
||||
#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 };
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
|
||||
#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__ )
|
||||
@ -204,13 +204,14 @@ ProcessList* ProcessList_new(UsersTable* usersTable) {
|
||||
this = malloc(sizeof(ProcessList));
|
||||
this->processes = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
||||
this->processTable = Hashtable_new(70, false);
|
||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||
this->prototype = Process_new(this);
|
||||
this->usersTable = usersTable;
|
||||
|
||||
/* tree-view auxiliary buffers */
|
||||
this->processes2 = Vector_new(PROCESS_CLASS, true, DEFAULT_SIZE, Process_compare);
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
this->traceFile = fopen("/tmp/htop-proc-trace", "w");
|
||||
#endif
|
||||
|
||||
@ -262,7 +263,7 @@ void ProcessList_delete(ProcessList* this) {
|
||||
// other fields are offsets of the same buffer
|
||||
free(this->totalTime);
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
fclose(this->traceFile);
|
||||
#endif
|
||||
|
||||
@ -297,14 +298,26 @@ void ProcessList_prune(ProcessList* this) {
|
||||
}
|
||||
|
||||
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);
|
||||
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) {
|
||||
Hashtable_remove(this->processTable, p->pid);
|
||||
assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1);
|
||||
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);
|
||||
assert(index != -1);
|
||||
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) {
|
||||
@ -318,21 +331,22 @@ int ProcessList_size(ProcessList* this) {
|
||||
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);
|
||||
|
||||
for (int i = 0; i < Vector_size(this->processes); i++) {
|
||||
for (int i = Vector_size(this->processes) - 1; i >= 0; i--) {
|
||||
Process* process = (Process*) (Vector_get(this->processes, i));
|
||||
if (process->ppid == pid) {
|
||||
Process* process = (Process*) (Vector_take(this->processes, i));
|
||||
Vector_add(children, process);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
int size = Vector_size(children);
|
||||
for (int i = 0; i < size; i++) {
|
||||
Process* process = (Process*) (Vector_get(children, i));
|
||||
int s = this->processes2->items;
|
||||
if (direction == 1)
|
||||
Vector_add(this->processes2, process);
|
||||
else
|
||||
Vector_insert(this->processes2, 0, process);
|
||||
assert(this->processes2->items == s+1); (void)s;
|
||||
int nextIndent = indent;
|
||||
if (i < size - 1)
|
||||
nextIndent = indent | (1 << level);
|
||||
@ -353,11 +367,19 @@ void ProcessList_sort(ProcessList* this) {
|
||||
Vector_sort(this->processes);
|
||||
this->sortKey = sortKey;
|
||||
this->direction = direction;
|
||||
int vsize = Vector_size(this->processes);
|
||||
Process* init = (Process*) (Vector_take(this->processes, 0));
|
||||
assert(init->pid == 1);
|
||||
init->indent = 0;
|
||||
Vector_add(this->processes2, init);
|
||||
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;
|
||||
this->processes = this->processes2;
|
||||
this->processes2 = t;
|
||||
@ -371,7 +393,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
int size = fread(buf, 1, MAX_READ, f);
|
||||
if(!size) return 0;
|
||||
|
||||
proc->pid = atoi(buf);
|
||||
assert(proc->pid == atoi(buf));
|
||||
char *location = strchr(buf, ' ');
|
||||
if(!location) return 0;
|
||||
|
||||
@ -384,9 +406,9 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
command[commsize] = '\0';
|
||||
location = end + 2;
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
int num = ProcessList_read(this, location,
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu "
|
||||
"%c %u %u %u %u %u %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
||||
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
||||
@ -395,7 +417,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
&proc->tpgid, &proc->flags,
|
||||
&proc->minflt, &proc->cminflt, &proc->majflt, &proc->cmajflt,
|
||||
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
||||
&proc->priority, &proc->nice, &zero, &proc->itrealvalue,
|
||||
&proc->priority, &proc->nice, &proc->nlwp, &proc->itrealvalue,
|
||||
&proc->starttime, &proc->vsize, &proc->rss, &proc->rlim,
|
||||
&proc->startcode, &proc->endcode, &proc->startstack, &proc->kstkesp,
|
||||
&proc->kstkeip, &proc->signal, &proc->blocked, &proc->sigignore,
|
||||
@ -404,7 +426,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
#else
|
||||
long int uzero;
|
||||
int num = ProcessList_read(this, location,
|
||||
"%c %d %d %d %d %d %lu %lu %lu %lu "
|
||||
"%c %u %u %u %u %u %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %ld %ld %ld %ld %ld %ld "
|
||||
"%lu %lu %ld %lu %lu %lu %lu %lu "
|
||||
"%lu %lu %lu %lu %lu %lu %lu %lu "
|
||||
@ -413,7 +435,7 @@ static int ProcessList_readStatFile(ProcessList* this, Process *proc, FILE *f, c
|
||||
&proc->tpgid, &proc->flags,
|
||||
&zero, &zero, &zero, &zero,
|
||||
&proc->utime, &proc->stime, &proc->cutime, &proc->cstime,
|
||||
&proc->priority, &proc->nice, &uzero, &uzero,
|
||||
&proc->priority, &proc->nice, &proc->nlwp, &uzero,
|
||||
&zero, &zero, &uzero, &zero,
|
||||
&zero, &zero, &zero, &zero,
|
||||
&zero, &zero, &zero, &zero,
|
||||
@ -477,7 +499,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
Process* prototype = this->prototype;
|
||||
|
||||
dir = opendir(dirname);
|
||||
assert(dir != NULL);
|
||||
if (!dir) return;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
char* name = entry->d_name;
|
||||
int pid;
|
||||
@ -508,14 +530,17 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
char statusfilename[MAX_NAME+1];
|
||||
char command[PROCESS_COMM_LEN + 1];
|
||||
|
||||
Process* process;
|
||||
Process* process = NULL;
|
||||
|
||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||
Process* existingProcess = (Process*) Hashtable_get(this->processTable, pid);
|
||||
if (existingProcess) {
|
||||
assert(Vector_indexOf(this->processes, existingProcess, Process_pidCompare) != -1);
|
||||
process = existingProcess;
|
||||
assert(process->pid == pid);
|
||||
} else {
|
||||
process = prototype;
|
||||
process->comm = NULL;
|
||||
assert(process->comm == NULL);
|
||||
process->pid = pid;
|
||||
if (! ProcessList_readStatusFile(this, process, dirname, name))
|
||||
goto errorReadingProcess;
|
||||
@ -530,7 +555,7 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
}
|
||||
int num = ProcessList_fread(this, status, "%d %d %d %d %d %d %d",
|
||||
&process->m_size, &process->m_resident, &process->m_share,
|
||||
&process->m_trs, &process->m_drs, &process->m_lrs,
|
||||
&process->m_trs, &process->m_lrs, &process->m_drs,
|
||||
&process->m_dt);
|
||||
|
||||
fclose(status);
|
||||
@ -577,8 +602,8 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
process->percent_cpu = (process->utime + process->stime - lasttimes) /
|
||||
period * 100.0;
|
||||
|
||||
process->percent_mem = process->m_resident /
|
||||
(float)(this->usedMem - this->cachedMem - this->buffersMem) *
|
||||
process->percent_mem = (process->m_resident * PAGE_SIZE) /
|
||||
(float)(this->totalMem) *
|
||||
100.0;
|
||||
|
||||
this->totalTasks++;
|
||||
@ -587,24 +612,23 @@ void ProcessList_processEntries(ProcessList* this, char* dirname, int parent, fl
|
||||
}
|
||||
|
||||
if (!existingProcess) {
|
||||
process = Process_clone(process);
|
||||
ProcessList_add(this, process);
|
||||
ProcessList_add(this, Process_clone(process));
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
// Exception handler.
|
||||
errorReadingProcess: {
|
||||
if (process->comm) {
|
||||
free(process->comm);
|
||||
process->comm = NULL;
|
||||
}
|
||||
if (existingProcess)
|
||||
ProcessList_remove(this, process);
|
||||
else {
|
||||
if (process->comm)
|
||||
free(process->comm);
|
||||
}
|
||||
assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
|
||||
}
|
||||
}
|
||||
}
|
||||
prototype->comm = NULL;
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,11 @@ in the source distribution for its full text.
|
||||
#endif
|
||||
|
||||
#ifndef PROCSTATFILE
|
||||
#define PROCSTATFILE "/proc/stat"
|
||||
#define PROCSTATFILE PROCDIR "/stat"
|
||||
#endif
|
||||
|
||||
#ifndef PROCMEMINFOFILE
|
||||
#define PROCMEMINFOFILE "/proc/meminfo"
|
||||
#define PROCMEMINFOFILE PROCDIR "/meminfo"
|
||||
#endif
|
||||
|
||||
#ifndef MAX_NAME
|
||||
@ -60,7 +60,7 @@ in the source distribution for its full text.
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
typedef int(*vxscanf)(void*, const char*, va_list);
|
||||
#endif
|
||||
|
||||
@ -118,13 +118,13 @@ typedef struct ProcessList_ {
|
||||
bool highlightBaseName;
|
||||
bool highlightMegabytes;
|
||||
bool expandSystemTime;
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
FILE* traceFile;
|
||||
#endif
|
||||
|
||||
} ProcessList;
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef DEBUG_PROC
|
||||
|
||||
#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__ )
|
||||
|
@ -35,7 +35,7 @@ void UsersTable_delete(UsersTable* this) {
|
||||
free(this);
|
||||
}
|
||||
|
||||
char* UsersTable_getRef(UsersTable* this, int uid) {
|
||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
||||
char* name = (char*) (Hashtable_get(this->users, uid));
|
||||
if (name == NULL) {
|
||||
struct passwd* userData = getpwuid(uid);
|
||||
|
@ -28,7 +28,7 @@ UsersTable* UsersTable_new();
|
||||
|
||||
void UsersTable_delete(UsersTable* this);
|
||||
|
||||
char* UsersTable_getRef(UsersTable* this, int uid);
|
||||
char* UsersTable_getRef(UsersTable* this, unsigned int uid);
|
||||
|
||||
inline int UsersTable_size(UsersTable* this);
|
||||
|
||||
|
14
Vector.c
14
Vector.c
@ -63,6 +63,7 @@ void Vector_delete(Vector* this) {
|
||||
#ifdef DEBUG
|
||||
|
||||
static inline bool Vector_isConsistent(Vector* this) {
|
||||
assert(this->items <= this->arraySize);
|
||||
if (this->owner) {
|
||||
for (int i = 0; i < this->items; i++)
|
||||
if (this->array[i] && this->array[i]->class != this->vectorType)
|
||||
@ -73,6 +74,16 @@ 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
|
||||
|
||||
void Vector_prune(Vector* this) {
|
||||
@ -222,8 +233,9 @@ void Vector_add(Vector* this, void* data_) {
|
||||
assert(data_ && ((Object*)data_)->class == this->vectorType);
|
||||
Object* data = data_;
|
||||
assert(Vector_isConsistent(this));
|
||||
|
||||
int i = this->items;
|
||||
Vector_set(this, this->items, data);
|
||||
assert(this->items == i+1); (void)(i);
|
||||
assert(Vector_isConsistent(this));
|
||||
}
|
||||
|
||||
|
2
Vector.h
2
Vector.h
@ -41,6 +41,8 @@ void Vector_delete(Vector* this);
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
int Vector_count(Vector* this);
|
||||
|
||||
#endif
|
||||
|
||||
void Vector_prune(Vector* this);
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ(2.57)
|
||||
AC_INIT([htop],[0.6.4],[loderunner@users.sourceforge.net])
|
||||
AC_INIT([htop],[0.6.6],[loderunner@users.sourceforge.net])
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_SRCDIR([htop.c])
|
||||
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"])
|
||||
|
||||
if test ! -z "$missing_libraries"; then
|
||||
AC_MSG_ERROR([missing libraries:$missing_headers])
|
||||
AC_MSG_ERROR([missing libraries: $missing_libraries])
|
||||
fi
|
||||
|
||||
# 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
|
||||
AC_MSG_ERROR([missing headers:$missing_headers])
|
||||
AC_MSG_ERROR([missing headers: $missing_headers])
|
||||
fi
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
|
2
htop.1
2
htop.1
@ -1,4 +1,4 @@
|
||||
.TH "htop" "1" "0.6.4" "Bartosz Fenski <fenio@o2.pl>" "Utils"
|
||||
.TH "htop" "1" "0.6.6" "Bartosz Fenski <fenio@o2.pl>" "Utils"
|
||||
.SH "NAME"
|
||||
htop \- interactive process viewer
|
||||
.SH "SYNTAX"
|
||||
|
57
htop.c
57
htop.c
@ -93,35 +93,36 @@ void showHelp(ProcessList* pl) {
|
||||
addattrstr(CRT_colors[BAR_BORDER], "]");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
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( 8, 0, " Arrows: scroll process list F5 t: tree view");
|
||||
mvaddstr( 9, 0, " Digits: incremental PID search u: show processes of a single user");
|
||||
mvaddstr(10, 0, " F3 /: incremental name search H: hide/show user threads");
|
||||
mvaddstr(11, 0, " K: hide/show kernel threads");
|
||||
mvaddstr(12, 0, " Space: tag processes F: cursor follows process");
|
||||
mvaddstr(13, 0, " U: untag all processes");
|
||||
mvaddstr(14, 0, " F9 k: kill process/tagged processes P: sort by CPU%");
|
||||
mvaddstr(15, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%");
|
||||
mvaddstr(16, 0, " - ] F8: higher priority (root only) T: sort by TIME");
|
||||
mvaddstr(17, 0, " F4 I: invert sort order");
|
||||
mvaddstr(18, 0, " F2 S: setup F6 >: select sort column");
|
||||
mvaddstr(19, 0, " F1 h: show this help screen");
|
||||
mvaddstr(20, 0, " F10 q: quit s: trace syscalls with strace");
|
||||
mvaddstr( 9, 0, " Arrows: scroll process list F5 t: tree view");
|
||||
mvaddstr(10, 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(12, 0, " K: hide/show kernel threads");
|
||||
mvaddstr(13, 0, " Space: tag processes F: cursor follows process");
|
||||
mvaddstr(14, 0, " U: untag all processes");
|
||||
mvaddstr(15, 0, " F9 k: kill process/tagged processes P: sort by CPU%");
|
||||
mvaddstr(16, 0, " + [ F7: lower priority (+ nice) M: sort by MEM%");
|
||||
mvaddstr(17, 0, " - ] F8: higher priority (root only) T: sort by TIME");
|
||||
mvaddstr(18, 0, " F4 I: invert sort order");
|
||||
mvaddstr(19, 0, " F2 S: setup F6 >: select sort column");
|
||||
mvaddstr(20, 0, " F1 h: show this help screen");
|
||||
mvaddstr(21, 0, " F10 q: quit s: trace syscalls with strace");
|
||||
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
mvaddstr( 8, 0, " Arrows"); mvaddstr( 8,40, " F5 t");
|
||||
mvaddstr( 9, 0, " Digits"); mvaddstr( 9,40, " u");
|
||||
mvaddstr(10, 0, " F3 /"); mvaddstr(10,40, " H");
|
||||
mvaddstr(11,40, " K");
|
||||
mvaddstr(12, 0, " Space"); mvaddstr(12,40, " F");
|
||||
mvaddstr(13, 0, " U");
|
||||
mvaddstr(14, 0, " F9 k"); mvaddstr(14,40, " P");
|
||||
mvaddstr(15, 0, " + [ F7"); mvaddstr(15,40, " M");
|
||||
mvaddstr(16, 0, " - ] F8"); mvaddstr(16,40, " T");
|
||||
mvaddstr(17,40, " F4 I");
|
||||
mvaddstr(18, 0, " F2 S"); mvaddstr(18,40, " F6 >");
|
||||
mvaddstr(19, 0, " F1 h");
|
||||
mvaddstr(20, 0, " F10 q"); mvaddstr(20,40, " s");
|
||||
mvaddstr( 9, 0, " Arrows"); mvaddstr( 9,40, " F5 t");
|
||||
mvaddstr(10, 0, " Digits"); mvaddstr(10,40, " u");
|
||||
mvaddstr(11, 0, " F3 /"); mvaddstr(11,40, " H");
|
||||
mvaddstr(12,40, " K");
|
||||
mvaddstr(13, 0, " Space"); mvaddstr(13,40, " F");
|
||||
mvaddstr(14, 0, " U");
|
||||
mvaddstr(15, 0, " F9 k"); mvaddstr(15,40, " P");
|
||||
mvaddstr(16, 0, " + [ F7"); mvaddstr(16,40, " M");
|
||||
mvaddstr(17, 0, " - ] F8"); mvaddstr(17,40, " T");
|
||||
mvaddstr(18,40, " F4 I");
|
||||
mvaddstr(19, 0, " F2 S"); mvaddstr(19,40, " F6 >");
|
||||
mvaddstr(20, 0, " F1 h");
|
||||
mvaddstr(21, 0, " F10 q"); mvaddstr(21,40, " s");
|
||||
attrset(CRT_colors[DEFAULT_COLOR]);
|
||||
|
||||
attrset(CRT_colors[HELP_BOLD]);
|
||||
@ -311,7 +312,7 @@ int main(int argc, char** argv) {
|
||||
incSearchIndex = 0;
|
||||
incSearchBuffer[0] = 0;
|
||||
int currPos = Panel_getSelectedIndex(panel);
|
||||
int currPid = 0;
|
||||
unsigned int currPid = 0;
|
||||
int currScrollV = panel->scrollV;
|
||||
if (follow)
|
||||
currPid = ProcessList_get(pl, currPos)->pid;
|
||||
@ -405,7 +406,7 @@ int main(int argc, char** argv) {
|
||||
continue;
|
||||
}
|
||||
if (isdigit((char)ch)) {
|
||||
int pid = ch-48 + acc;
|
||||
unsigned int pid = ch-48 + acc;
|
||||
for (int i = 0; i < ProcessList_size(pl) && ((Process*) Panel_getSelected(panel))->pid != pid; i++)
|
||||
Panel_setSelected(panel, i);
|
||||
acc = pid * 10;
|
||||
|
@ -1,6 +1,6 @@
|
||||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Version=0.6.4
|
||||
Version=0.6.6
|
||||
Name=Htop
|
||||
Type=Application
|
||||
Comment=Show System Processes
|
||||
|
@ -21,6 +21,8 @@ class writer:
|
||||
self.file.write(text + "\n")
|
||||
out = writer(out)
|
||||
|
||||
print("Generating "+name+".h")
|
||||
|
||||
selfheader = '#include "' + name + '.h"'
|
||||
|
||||
out.write( "/* Do not edit this file. It was automatically generated. */" )
|
||||
|
Reference in New Issue
Block a user