mirror of https://github.com/xzeldon/htop.git
Move "get max pid" code into platform specific area.
This commit is contained in:
parent
5578a316f0
commit
b4f6b11092
10
Process.c
10
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 <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
@ -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 ";
|
||||
|
|
|
@ -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)
|
||||
|
|
2
htop.c
2
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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,3 +54,7 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
|||
*five = 0;
|
||||
*fifteen = 0;
|
||||
}
|
||||
|
||||
int Platform_getMaxPid() {
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue