Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: /proc/<pid>/status refactor no2 #1222

Merged
merged 6 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Process.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void Process_writeField(const Process* this, RichString* str, RowField field) {
}
break;
case USER:
if (this->elevated_priv)
if (this->elevated_priv == TRI_ON)
attr = CRT_colors[PROCESS_PRIV];
else if (host->htopUserId != this->st_uid)
attr = CRT_colors[PROCESS_SHADOW];
Expand Down
11 changes: 9 additions & 2 deletions Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ in the source distribution for its full text.

#define DEFAULT_HIGHLIGHT_SECS 5

typedef enum Tristate_ {
TRI_INITIAL = 0,
TRI_OFF = -1,
TRI_ON = 1,
} Tristate;


/* Core process states (shared by platforms)
* NOTE: The enum has an ordering that is important!
* See processStateChar in process.c for ProcessSate -> letter mapping */
Expand Down Expand Up @@ -87,7 +94,7 @@ typedef struct Process_ {
bool isUserlandThread;

/* This process is running inside a container */
bool isRunningInContainer;
Tristate isRunningInContainer;

/* Controlling terminal identifier of the process */
unsigned long int tty_nr;
Expand All @@ -106,7 +113,7 @@ typedef struct Process_ {
* - from file capabilities
* - inherited from the ambient set
*/
bool elevated_priv;
Tristate elevated_priv;

/* Process runtime (in hundredth of a second) */
unsigned long long int time;
Expand Down
3 changes: 3 additions & 0 deletions Scheduling.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ const char* Scheduling_formatPolicy(int policy) {
}
}

/*
* Gather scheduling policy (thread-specific data)
*/
void Scheduling_readProcessPolicy(Process* proc) {
proc->scheduling_policy = sched_getscheduler(Process_getPid(proc));
}
Expand Down
3 changes: 3 additions & 0 deletions linux/LibNl.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) {
return NL_OK;
}

/*
* Gather delay-accounting information (thread-specific data)
*/
void LibNl_readDelayAcctData(LinuxProcessTable* this, LinuxProcess* process) {
struct nl_msg* msg;

Expand Down
19 changes: 19 additions & 0 deletions linux/LinuxProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
[CWD] = { .name = "CWD", .title = "CWD ", .description = "The current working directory of the process", .flags = PROCESS_FLAG_CWD, },
[AUTOGROUP_ID] = { .name = "AUTOGROUP_ID", .title = "AGRP", .description = "The autogroup identifier of the process", .flags = PROCESS_FLAG_LINUX_AUTOGROUP, },
[AUTOGROUP_NICE] = { .name = "AUTOGROUP_NICE", .title = " ANI", .description = "Nice value (the higher the value, the more other processes take priority) associated with the process autogroup", .flags = PROCESS_FLAG_LINUX_AUTOGROUP, },
[ISCONTAINER] = { .name = "ISCONTAINER", .title = "CONT ", .description = "Whether the process is running inside a child container", .flags = PROCESS_FLAG_LINUX_CONTAINER, },
#ifdef SCHEDULER_SUPPORT
[SCHEDULERPOLICY] = { .name = "SCHEDULERPOLICY", .title = "SCHED ", .description = "Current scheduling policy of the process", .flags = PROCESS_FLAG_SCHEDPOL, },
#endif
Expand Down Expand Up @@ -154,6 +155,9 @@ static int LinuxProcess_effectiveIOPriority(const LinuxProcess* this) {
#define SYS_ioprio_set __NR_ioprio_set
#endif

/*
* Gather I/O scheduling class and priority (thread-specific data)
*/
IOPriority LinuxProcess_updateIOPriority(Process* p) {
IOPriority ioprio = 0;
// Other OSes masquerading as Linux (NetBSD?) don't have this syscall
Expand Down Expand Up @@ -333,6 +337,19 @@ static void LinuxProcess_rowWriteField(const Row* super, RichString* str, Proces
xSnprintf(buffer, n, "N/A ");
}
break;
case ISCONTAINER:
switch (this->isRunningInContainer) {
case TRI_ON:
xSnprintf(buffer, n, "YES ");
break;
case TRI_OFF:
xSnprintf(buffer, n, "NO ");
break;
default:
attr = CRT_colors[PROCESS_SHADOW];
xSnprintf(buffer, n, "N/A ");
}
break;
default:
Process_writeField(this, str, field);
return;
Expand Down Expand Up @@ -435,6 +452,8 @@ static int LinuxProcess_compareByKey(const Process* v1, const Process* v2, Proce
}
case GPU_TIME:
return SPACESHIP_NUMBER(p1->gpu_time, p2->gpu_time);
case ISCONTAINER:
return SPACESHIP_NUMBER(v1->isRunningInContainer, v2->isRunningInContainer);
default:
return Process_compareByKey_Base(v1, v2, key);
}
Expand Down
1 change: 1 addition & 0 deletions linux/LinuxProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ in the source distribution for its full text.
#define PROCESS_FLAG_LINUX_DELAYACCT 0x00040000
#define PROCESS_FLAG_LINUX_AUTOGROUP 0x00080000
#define PROCESS_FLAG_LINUX_GPU 0x00100000
#define PROCESS_FLAG_LINUX_CONTAINER 0x00200000

typedef struct LinuxProcess_ {
Process super;
Expand Down
Loading