mirror of https://github.com/xzeldon/htop.git
Use wider PID columns in 64-bit machines with larger pid_max values.
This commit is contained in:
parent
d25a0bc213
commit
75080ce79d
38
Process.c
38
Process.c
|
@ -228,6 +228,32 @@ const char *Process_fieldTitles[] = {
|
|||
|
||||
static int Process_getuid = -1;
|
||||
|
||||
static char* Process_pidFormat = "%7u ";
|
||||
static char* Process_tpgidFormat = "%7u ";
|
||||
|
||||
void Process_getMaxPid() {
|
||||
FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r");
|
||||
if (!file) return;
|
||||
int maxPid = 4194303;
|
||||
fscanf(file, "%d", &maxPid);
|
||||
fclose(file);
|
||||
if (maxPid > 99999) {
|
||||
Process_fieldTitles[PID] = " PID ";
|
||||
Process_fieldTitles[PPID] = " PPID ";
|
||||
Process_fieldTitles[TPGID] = " TPGID ";
|
||||
Process_fieldTitles[TGID] = " TGID ";
|
||||
Process_pidFormat = "%7u ";
|
||||
Process_tpgidFormat = "%7d ";
|
||||
} else {
|
||||
Process_fieldTitles[PID] = " PID ";
|
||||
Process_fieldTitles[PPID] = " PPID ";
|
||||
Process_fieldTitles[TPGID] = "TPGID ";
|
||||
Process_fieldTitles[TGID] = " TGID ";
|
||||
Process_pidFormat = "%5u ";
|
||||
Process_tpgidFormat = "%5d ";
|
||||
}
|
||||
}
|
||||
|
||||
#define ONE_K 1024
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
#define ONE_G (ONE_M * ONE_K)
|
||||
|
@ -341,13 +367,13 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
|
|||
int n = sizeof(buffer) - 1;
|
||||
|
||||
switch (field) {
|
||||
case PID: snprintf(buffer, n, "%5u ", this->pid); break;
|
||||
case PPID: snprintf(buffer, n, "%5u ", this->ppid); break;
|
||||
case PID: snprintf(buffer, n, Process_pidFormat, this->pid); break;
|
||||
case PPID: snprintf(buffer, n, Process_pidFormat, 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 TGID: snprintf(buffer, n, "%5u ", this->tgid); break;
|
||||
case TPGID: snprintf(buffer, n, "%5d ", this->tpgid); break;
|
||||
case TGID: snprintf(buffer, n, Process_pidFormat, this->tgid); break;
|
||||
case TPGID: snprintf(buffer, n, Process_tpgidFormat, this->tpgid); break;
|
||||
case PROCESSOR: snprintf(buffer, n, "%3d ", ProcessList_cpuId(this->pl, this->processor)); break;
|
||||
case NLWP: snprintf(buffer, n, "%4ld ", this->nlwp); break;
|
||||
case COMM: {
|
||||
|
@ -456,8 +482,8 @@ static void Process_writeField(Process* this, RichString* str, ProcessField fiel
|
|||
case VXID: snprintf(buffer, n, "%5u ", this->vxid); break;
|
||||
#endif
|
||||
#ifdef HAVE_TASKSTATS
|
||||
case RCHAR: snprintf(buffer, n, "%10llu ", this->io_rchar); break;
|
||||
case WCHAR: snprintf(buffer, n, "%10llu ", this->io_wchar); break;
|
||||
case RCHAR: snprintf(buffer, n, "%12llu ", this->io_rchar); break;
|
||||
case WCHAR: snprintf(buffer, n, "%12llu ", this->io_wchar); break;
|
||||
case SYSCR: snprintf(buffer, n, "%10llu ", this->io_syscr); break;
|
||||
case SYSCW: snprintf(buffer, n, "%10llu ", this->io_syscw); break;
|
||||
case RBYTES: Process_colorNumber(this, str, this->io_read_bytes); return;
|
||||
|
|
|
@ -181,6 +181,9 @@ extern const char *Process_fieldNames[];
|
|||
|
||||
extern const char *Process_fieldTitles[];
|
||||
|
||||
|
||||
void Process_getMaxPid();
|
||||
|
||||
#define ONE_K 1024
|
||||
#define ONE_M (ONE_K * ONE_K)
|
||||
#define ONE_G (ONE_M * ONE_K)
|
||||
|
|
Loading…
Reference in New Issue