diff --git a/Process.c b/Process.c index 7fc36a1a..de25cbbb 100644 --- a/Process.c +++ b/Process.c @@ -11,6 +11,7 @@ in the source distribution for its full text. #include "CRT.h" #include "String.h" #include "RichString.h" +#include "Platform.h" #include #include @@ -284,12 +285,9 @@ 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, "%32d", &maxPid); - fclose(file); +void Process_setupColumnWidths() { + int maxPid = Platform_getMaxPid(); + if (maxPid == -1) return; if (maxPid > 99999) { Process_fieldTitles[PID] = " PID "; Process_fieldTitles[PPID] = " PPID "; diff --git a/Process.h b/Process.h index c4ef808d..6bd40686 100644 --- a/Process.h +++ b/Process.h @@ -179,7 +179,7 @@ extern const int Process_fieldFlags[]; extern const char *Process_fieldTitles[]; -void Process_getMaxPid(); +void Process_setupColumnWidths(); #define ONE_K 1024L #define ONE_M (ONE_K * ONE_K) diff --git a/htop.c b/htop.c index e70c270d..66088e7a 100644 --- a/htop.c +++ b/htop.c @@ -680,7 +680,7 @@ int main(int argc, char** argv) { ProcessList* pl = ProcessList_new(ut, pidWhiteList); pl->userOnly = userOnly; pl->userId = userId; - Process_getMaxPid(); + Process_setupColumnWidths(); Header* header = Header_new(pl); Settings* settings = Settings_new(pl, header, pl->cpuCount); diff --git a/linux/Platform.c b/linux/Platform.c index ebd10331..4607ad68 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -93,3 +93,12 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } } +int Platform_getMaxPid() { + FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); + if (!file) return -1; + int maxPid = 4194303; + fscanf(file, "%32d", &maxPid); + fclose(file); + return maxPid; +} + diff --git a/unsupported/Platform.c b/unsupported/Platform.c index b13b495b..764f890e 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -54,3 +54,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { *five = 0; *fifteen = 0; } + +int Platform_getMaxPid() { + return -1; +}