mirror of https://github.com/xzeldon/htop.git
parent
8bd603cb68
commit
9428010121
30
Process.c
30
Process.c
|
@ -26,6 +26,7 @@ in the source distribution for its full text.
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
#define SYS_ioprio_get __NR_ioprio_get
|
#define SYS_ioprio_get __NR_ioprio_get
|
||||||
|
@ -72,6 +73,11 @@ typedef enum ProcessFields {
|
||||||
TGID = 52,
|
TGID = 52,
|
||||||
} ProcessField;
|
} ProcessField;
|
||||||
|
|
||||||
|
typedef struct ProcessPidColumn_ {
|
||||||
|
int id;
|
||||||
|
char* label;
|
||||||
|
} ProcessPidColumn;
|
||||||
|
|
||||||
typedef struct Process_ {
|
typedef struct Process_ {
|
||||||
Object super;
|
Object super;
|
||||||
|
|
||||||
|
@ -145,14 +151,13 @@ typedef struct ProcessFieldData_ {
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
void Process_setupColumnWidths();
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
long Process_compare(const void* v1, const void* v2);
|
long Process_compare(const void* v1, const void* v2);
|
||||||
void Process_delete(Object* cast);
|
void Process_delete(Object* cast);
|
||||||
bool Process_isThread(Process* this);
|
bool Process_isThread(Process* this);
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
extern char* Process_pidFormat;
|
extern ProcessPidColumn Process_pidColumns[];
|
||||||
extern char* Process_tpgidFormat;
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
typedef Process*(*Process_New)(struct Settings_*);
|
typedef Process*(*Process_New)(struct Settings_*);
|
||||||
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
|
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
|
||||||
|
@ -176,6 +181,23 @@ static int Process_getuid = -1;
|
||||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||||
|
|
||||||
|
char Process_pidFormat[20] = "%7u ";
|
||||||
|
|
||||||
|
static char Process_titleBuffer[20][20];
|
||||||
|
|
||||||
|
void Process_setupColumnWidths() {
|
||||||
|
int maxPid = Platform_getMaxPid();
|
||||||
|
if (maxPid == -1) return;
|
||||||
|
int digits = ceil(log10(maxPid));
|
||||||
|
assert(digits < 20);
|
||||||
|
for (int i = 0; Process_pidColumns[i].label; i++) {
|
||||||
|
assert(i < 20);
|
||||||
|
sprintf(Process_titleBuffer[i], "%*s ", digits, Process_pidColumns[i].label);
|
||||||
|
Process_fields[Process_pidColumns[i].id].title = Process_titleBuffer[i];
|
||||||
|
}
|
||||||
|
sprintf(Process_pidFormat, "%%%du ", digits);
|
||||||
|
}
|
||||||
|
|
||||||
void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
void Process_humanNumber(RichString* str, unsigned long number, bool coloring) {
|
||||||
char buffer[11];
|
char buffer[11];
|
||||||
int len;
|
int len;
|
||||||
|
@ -426,7 +448,7 @@ void Process_writeField(Process* this, RichString* str, ProcessField field) {
|
||||||
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
|
case ST_UID: snprintf(buffer, n, "%4d ", this->st_uid); break;
|
||||||
case TIME: Process_printTime(str, this->time); return;
|
case TIME: Process_printTime(str, this->time); return;
|
||||||
case TGID: snprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
case TGID: snprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
||||||
case TPGID: snprintf(buffer, n, Process_tpgidFormat, this->tpgid); break;
|
case TPGID: snprintf(buffer, n, Process_pidFormat, this->tpgid); break;
|
||||||
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
case TTY_NR: snprintf(buffer, n, "%5u ", this->tty_nr); break;
|
||||||
case USER: {
|
case USER: {
|
||||||
if (Process_getuid != (int) this->st_uid)
|
if (Process_getuid != (int) this->st_uid)
|
||||||
|
|
14
Process.h
14
Process.h
|
@ -53,6 +53,11 @@ typedef enum ProcessFields {
|
||||||
TGID = 52,
|
TGID = 52,
|
||||||
} ProcessField;
|
} ProcessField;
|
||||||
|
|
||||||
|
typedef struct ProcessPidColumn_ {
|
||||||
|
int id;
|
||||||
|
char* label;
|
||||||
|
} ProcessPidColumn;
|
||||||
|
|
||||||
typedef struct Process_ {
|
typedef struct Process_ {
|
||||||
Object super;
|
Object super;
|
||||||
|
|
||||||
|
@ -126,14 +131,13 @@ typedef struct ProcessFieldData_ {
|
||||||
} ProcessFieldData;
|
} ProcessFieldData;
|
||||||
|
|
||||||
// Implemented in platform-specific code:
|
// Implemented in platform-specific code:
|
||||||
void Process_setupColumnWidths();
|
|
||||||
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
void Process_writeField(Process* this, RichString* str, ProcessField field);
|
||||||
long Process_compare(const void* v1, const void* v2);
|
long Process_compare(const void* v1, const void* v2);
|
||||||
void Process_delete(Object* cast);
|
void Process_delete(Object* cast);
|
||||||
bool Process_isThread(Process* this);
|
bool Process_isThread(Process* this);
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
extern char* Process_pidFormat;
|
extern ProcessPidColumn Process_pidColumns[];
|
||||||
extern char* Process_tpgidFormat;
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
typedef Process*(*Process_New)(struct Settings_*);
|
typedef Process*(*Process_New)(struct Settings_*);
|
||||||
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
|
typedef void (*Process_WriteField)(Process*, RichString*, ProcessField);
|
||||||
|
@ -154,6 +158,10 @@ typedef struct ProcessClass_ {
|
||||||
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
|
||||||
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
|
||||||
|
|
||||||
|
extern char Process_pidFormat[20];
|
||||||
|
|
||||||
|
void Process_setupColumnWidths();
|
||||||
|
|
||||||
void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
void Process_humanNumber(RichString* str, unsigned long number, bool coloring);
|
||||||
|
|
||||||
void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
void Process_colorNumber(RichString* str, unsigned long long number, bool coloring);
|
||||||
|
|
|
@ -82,7 +82,6 @@ void Platform_setBindings(Htop_Action* keys) {
|
||||||
|
|
||||||
int Platform_numberOfFields = 100;
|
int Platform_numberOfFields = 100;
|
||||||
char* Process_pidFormat = "%7u ";
|
char* Process_pidFormat = "%7u ";
|
||||||
char* Process_tpgidFormat = "%7u ";
|
|
||||||
|
|
||||||
int Platform_getUptime() {
|
int Platform_getUptime() {
|
||||||
struct timeval bootTime, currTime;
|
struct timeval bootTime, currTime;
|
||||||
|
@ -117,29 +116,15 @@ int Platform_getMaxPid() {
|
||||||
return 99999;
|
return 99999;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process_setupColumnWidths() {
|
ProcessPidColumn Process_pidColumns[] = {
|
||||||
int maxPid = Platform_getMaxPid();
|
{ .id = PID, .label = "PID" },
|
||||||
if (maxPid == -1) return;
|
{ .id = PPID, .label = "PPID" },
|
||||||
if (maxPid > 99999) {
|
{ .id = TPGID, .label = "TPGID" },
|
||||||
Process_fields[PID].title = " PID ";
|
{ .id = TGID, .label = "TGID" },
|
||||||
Process_fields[PPID].title = " PPID ";
|
{ .id = PGRP, .label = "PGRP" },
|
||||||
Process_fields[TPGID].title = " TPGID ";
|
{ .id = SESSION, .label = "SESN" },
|
||||||
Process_fields[TGID].title = " TGID ";
|
{ .id = 0, .label = NULL },
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
};
|
||||||
Process_fields[SESSION].title = " SESN ";
|
|
||||||
Process_pidFormat = "%7u ";
|
|
||||||
Process_tpgidFormat = "%7d ";
|
|
||||||
} else {
|
|
||||||
Process_fields[PID].title = " PID ";
|
|
||||||
Process_fields[PPID].title = " PPID ";
|
|
||||||
Process_fields[TPGID].title = "TPGID ";
|
|
||||||
Process_fields[TGID].title = " TGID ";
|
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
|
||||||
Process_fields[SESSION].title = " SESN ";
|
|
||||||
Process_pidFormat = "%5u ";
|
|
||||||
Process_tpgidFormat = "%5d ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double Platform_setCPUValues(Meter* mtr, int cpu) {
|
double Platform_setCPUValues(Meter* mtr, int cpu) {
|
||||||
/* All just from CPUMeter.c */
|
/* All just from CPUMeter.c */
|
||||||
|
|
|
@ -24,7 +24,6 @@ void Platform_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
extern char* Process_pidFormat;
|
extern char* Process_pidFormat;
|
||||||
extern char* Process_tpgidFormat;
|
|
||||||
|
|
||||||
int Platform_getUptime();
|
int Platform_getUptime();
|
||||||
|
|
||||||
|
@ -32,8 +31,6 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||||
|
|
||||||
int Platform_getMaxPid();
|
int Platform_getMaxPid();
|
||||||
|
|
||||||
void Process_setupColumnWidths();
|
|
||||||
|
|
||||||
double Platform_setCPUValues(Meter* mtr, int cpu);
|
double Platform_setCPUValues(Meter* mtr, int cpu);
|
||||||
|
|
||||||
void Platform_setMemoryValues(Meter* mtr);
|
void Platform_setMemoryValues(Meter* mtr);
|
||||||
|
|
|
@ -75,32 +75,15 @@ ProcessFieldData Process_fields[] = {
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
char* Process_pidFormat = "%7u ";
|
ProcessPidColumn Process_pidColumns[] = {
|
||||||
char* Process_tpgidFormat = "%7u ";
|
{ .id = PID, .label = "PID" },
|
||||||
|
{ .id = PPID, .label = "PPID" },
|
||||||
void Process_setupColumnWidths() {
|
{ .id = TPGID, .label = "TPGID" },
|
||||||
int maxPid = Platform_getMaxPid();
|
{ .id = TGID, .label = "TGID" },
|
||||||
if (maxPid == -1) return;
|
{ .id = PGRP, .label = "PGRP" },
|
||||||
if (maxPid > 99999) {
|
{ .id = SESSION, .label = "SESN" },
|
||||||
Process_fields[PID].title = " PID ";
|
{ .id = 0, .label = NULL },
|
||||||
Process_fields[PPID].title = " PPID ";
|
};
|
||||||
Process_fields[TPGID].title = " TPGID ";
|
|
||||||
Process_fields[TGID].title = " TGID ";
|
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
|
||||||
Process_fields[SESSION].title = " SESN ";
|
|
||||||
Process_pidFormat = "%7u ";
|
|
||||||
Process_tpgidFormat = "%7d ";
|
|
||||||
} else {
|
|
||||||
Process_fields[PID].title = " PID ";
|
|
||||||
Process_fields[PPID].title = " PPID ";
|
|
||||||
Process_fields[TPGID].title = "TPGID ";
|
|
||||||
Process_fields[TGID].title = " TGID ";
|
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
|
||||||
Process_fields[SESSION].title = " SESN ";
|
|
||||||
Process_pidFormat = "%5u ";
|
|
||||||
Process_tpgidFormat = "%5d ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FreeBSDProcess* FreeBSDProcess_new(Settings* settings) {
|
FreeBSDProcess* FreeBSDProcess_new(Settings* settings) {
|
||||||
FreeBSDProcess* this = calloc(sizeof(FreeBSDProcess), 1);
|
FreeBSDProcess* this = calloc(sizeof(FreeBSDProcess), 1);
|
||||||
|
|
|
@ -33,9 +33,6 @@ extern ProcessClass FreeBSDProcess_class;
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
extern char* Process_pidFormat;
|
extern char* Process_pidFormat;
|
||||||
extern char* Process_tpgidFormat;
|
|
||||||
|
|
||||||
void Process_setupColumnWidths();
|
|
||||||
|
|
||||||
FreeBSDProcess* FreeBSDProcess_new(Settings* settings);
|
FreeBSDProcess* FreeBSDProcess_new(Settings* settings);
|
||||||
|
|
||||||
|
|
|
@ -217,40 +217,19 @@ ProcessFieldData Process_fields[] = {
|
||||||
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
[LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, },
|
||||||
};
|
};
|
||||||
|
|
||||||
char* Process_pidFormat = "%7u ";
|
ProcessPidColumn Process_pidColumns[] = {
|
||||||
char* Process_tpgidFormat = "%7u ";
|
{ .id = PID, .label = "PID" },
|
||||||
|
{ .id = PPID, .label = "PPID" },
|
||||||
void Process_setupColumnWidths() {
|
|
||||||
int maxPid = Platform_getMaxPid();
|
|
||||||
if (maxPid == -1) return;
|
|
||||||
if (maxPid > 99999) {
|
|
||||||
Process_fields[PID].title = " PID ";
|
|
||||||
Process_fields[PPID].title = " PPID ";
|
|
||||||
#ifdef HAVE_OPENVZ
|
#ifdef HAVE_OPENVZ
|
||||||
Process_fields[VPID].title = " VPID ";
|
{ .id = VPID, .label = "VPID" },
|
||||||
#endif
|
#endif
|
||||||
Process_fields[TPGID].title = " TPGID ";
|
{ .id = TPGID, .label = "TPGID" },
|
||||||
Process_fields[TGID].title = " TGID ";
|
{ .id = TGID, .label = "TGID" },
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
{ .id = PGRP, .label = "PGRP" },
|
||||||
Process_fields[SESSION].title = " SESN ";
|
{ .id = SESSION, .label = "SESN" },
|
||||||
Process_fields[OOM].title = " OOM ";
|
{ .id = OOM, .label = "OOM" },
|
||||||
Process_pidFormat = "%7u ";
|
{ .id = 0, .label = NULL },
|
||||||
Process_tpgidFormat = "%7d ";
|
};
|
||||||
} else {
|
|
||||||
Process_fields[PID].title = " PID ";
|
|
||||||
Process_fields[PPID].title = " PPID ";
|
|
||||||
#ifdef HAVE_OPENVZ
|
|
||||||
Process_fields[VPID].title = " VPID ";
|
|
||||||
#endif
|
|
||||||
Process_fields[TPGID].title = "TPGID ";
|
|
||||||
Process_fields[TGID].title = " TGID ";
|
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
|
||||||
Process_fields[SESSION].title = " SESN ";
|
|
||||||
Process_fields[OOM].title = " OOM ";
|
|
||||||
Process_pidFormat = "%5u ";
|
|
||||||
Process_tpgidFormat = "%5d ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProcessClass LinuxProcess_class = {
|
ProcessClass LinuxProcess_class = {
|
||||||
.super = {
|
.super = {
|
||||||
|
|
|
@ -129,10 +129,7 @@ typedef struct LinuxProcess_ {
|
||||||
|
|
||||||
extern ProcessFieldData Process_fields[];
|
extern ProcessFieldData Process_fields[];
|
||||||
|
|
||||||
extern char* Process_pidFormat;
|
extern ProcessPidColumn Process_pidColumns[];
|
||||||
extern char* Process_tpgidFormat;
|
|
||||||
|
|
||||||
void Process_setupColumnWidths();
|
|
||||||
|
|
||||||
extern ProcessClass LinuxProcess_class;
|
extern ProcessClass LinuxProcess_class;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,6 @@ void Platform_setBindings(Htop_Action* keys) {
|
||||||
|
|
||||||
int Platform_numberOfFields = 100;
|
int Platform_numberOfFields = 100;
|
||||||
char* Process_pidFormat = "%7u ";
|
char* Process_pidFormat = "%7u ";
|
||||||
char* Process_tpgidFormat = "%7u ";
|
|
||||||
|
|
||||||
int Platform_getUptime() {
|
int Platform_getUptime() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -107,7 +106,6 @@ void Process_setupColumnWidths() {
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
Process_fields[PGRP].title = " PGRP ";
|
||||||
Process_fields[SESSION].title = " SESN ";
|
Process_fields[SESSION].title = " SESN ";
|
||||||
Process_pidFormat = "%7u ";
|
Process_pidFormat = "%7u ";
|
||||||
Process_tpgidFormat = "%7d ";
|
|
||||||
} else {
|
} else {
|
||||||
Process_fields[PID].title = " PID ";
|
Process_fields[PID].title = " PID ";
|
||||||
Process_fields[PPID].title = " PPID ";
|
Process_fields[PPID].title = " PPID ";
|
||||||
|
@ -116,7 +114,6 @@ void Process_setupColumnWidths() {
|
||||||
Process_fields[PGRP].title = " PGRP ";
|
Process_fields[PGRP].title = " PGRP ";
|
||||||
Process_fields[SESSION].title = " SESN ";
|
Process_fields[SESSION].title = " SESN ";
|
||||||
Process_pidFormat = "%5u ";
|
Process_pidFormat = "%5u ";
|
||||||
Process_tpgidFormat = "%5d ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ void Platform_setBindings(Htop_Action* keys);
|
||||||
|
|
||||||
extern int Platform_numberOfFields;
|
extern int Platform_numberOfFields;
|
||||||
extern char* Process_pidFormat;
|
extern char* Process_pidFormat;
|
||||||
extern char* Process_tpgidFormat;
|
|
||||||
|
|
||||||
int Platform_getUptime();
|
int Platform_getUptime();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue