mirror of https://github.com/xzeldon/htop.git
Adds support for PROC_EXE and CWD.
This commit is contained in:
parent
612462e33d
commit
336acb0309
|
@ -195,6 +195,19 @@ const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = {
|
|||
.description = "comm string of the process",
|
||||
.flags = 0,
|
||||
},
|
||||
[PROC_EXE] = {
|
||||
.name = "EXE",
|
||||
.title = "EXE ",
|
||||
.description = "Basename of exe of the process",
|
||||
.flags = 0,
|
||||
},
|
||||
[CWD] = {
|
||||
.name = "CWD",
|
||||
.title = "CWD ",
|
||||
.description = "The current working directory of the process",
|
||||
.flags = PROCESS_FLAG_CWD,
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Process* NetBSDProcess_new(const Settings* settings) {
|
||||
|
|
|
@ -114,6 +114,44 @@ static void NetBSDProcessList_scanMemoryInfo(ProcessList* pl) {
|
|||
pl->usedSwap = uvmexp.swpginuse * pageSizeKB;
|
||||
}
|
||||
|
||||
static void NetBSDProcessList_updateExe(const struct kinfo_proc2* kproc, Process* proc) {
|
||||
const int mib[] = { CTL_KERN, KERN_PROC_ARGS, kproc->p_pid, KERN_PROC_PATHNAME };
|
||||
char buffer[2048];
|
||||
size_t size = sizeof(buffer);
|
||||
if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) {
|
||||
Process_updateExe(proc, NULL);
|
||||
return;
|
||||
}
|
||||
printf("%s\n", buffer);
|
||||
/* Kernel threads return an empty buffer */
|
||||
if (buffer[0] == '\0') {
|
||||
Process_updateExe(proc, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
Process_updateExe(proc, buffer);
|
||||
}
|
||||
|
||||
static void NetBSDProcessList_updateCwd(const struct kinfo_proc2* kproc, Process* proc) {
|
||||
const int mib[] = { CTL_KERN, KERN_PROC_ARGS, kproc->p_pid, KERN_PROC_CWD };
|
||||
char buffer[2048];
|
||||
size_t size = sizeof(buffer);
|
||||
if (sysctl(mib, 4, buffer, &size, NULL, 0) != 0) {
|
||||
free(proc->procCwd);
|
||||
proc->procCwd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Kernel threads return an empty buffer */
|
||||
if (buffer[0] == '\0') {
|
||||
free(proc->procCwd);
|
||||
proc->procCwd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
free_and_xStrdup(&proc->procCwd, buffer);
|
||||
}
|
||||
|
||||
static void NetBSDProcessList_updateProcessName(kvm_t* kd, const struct kinfo_proc2* kproc, Process* proc) {
|
||||
Process_updateComm(proc, kproc->p_comm);
|
||||
|
||||
|
@ -203,6 +241,7 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
|
|||
proc->user = UsersTable_getRef(this->super.usersTable, proc->st_uid);
|
||||
ProcessList_add(&this->super, proc);
|
||||
|
||||
NetBSDProcessList_updateExe(kproc, proc);
|
||||
NetBSDProcessList_updateProcessName(this->kd, kproc, proc);
|
||||
} else {
|
||||
if (settings->updateProcessNames) {
|
||||
|
@ -210,6 +249,10 @@ static void NetBSDProcessList_scanProcs(NetBSDProcessList* this) {
|
|||
}
|
||||
}
|
||||
|
||||
if (settings->flags & PROCESS_FLAG_CWD) {
|
||||
NetBSDProcessList_updateCwd(kproc, proc);
|
||||
}
|
||||
|
||||
proc->m_virt = kproc->p_vm_vsize;
|
||||
proc->m_resident = kproc->p_vm_rssize;
|
||||
proc->percent_mem = (proc->m_resident * pageSizeKB) / (double)(this->super.totalMem) * 100.0;
|
||||
|
|
Loading…
Reference in New Issue