Skip to content

Commit

Permalink
darwin: not every process should be in running state (htop-dev#1611)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 22, 2025
1 parent fe73c2f commit 376afa9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 31 deletions.
16 changes: 3 additions & 13 deletions darwin/DarwinProcess.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ void DarwinProcess_setFromKInfoProc(Process* proc, const struct kinfo_proc* ps,
void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable* dpt, double timeIntervalNS) {
struct proc_taskinfo pti;

if (sizeof(pti) != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) {
if (PROC_PIDTASKINFO_SIZE != proc_pidinfo(Process_getPid(&proc->super), PROC_PIDTASKINFO, 0, &pti, PROC_PIDTASKINFO_SIZE)) {
proc->taskAccess = false;
return;
}

Expand All @@ -390,6 +391,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessTable
}
Process_updateCPUFieldWidths(proc->super.percent_cpu);

proc->super.state = pti.pti_numrunning > 0 ? RUNNING : SLEEPING;
proc->super.time = nanosecondsToCentiseconds(total_current_time_ns);
proc->super.nlwp = pti.pti_threadnum;
proc->super.m_virt = pti.pti_virtual_size / ONE_K;
Expand Down Expand Up @@ -435,18 +437,6 @@ void DarwinProcess_scanThreads(DarwinProcess* dp, DarwinProcessTable* dpt) {
return;
}

{
task_info_data_t tinfo;
mach_msg_type_number_t task_info_count = TASK_INFO_MAX;
ret = task_info(task, TASK_BASIC_INFO, (task_info_t) &tinfo, &task_info_count);
if (ret != KERN_SUCCESS) {
CRT_debug("task_info(%d) failed: %s", pid, mach_error_string(ret));
dp->taskAccess = false;
mach_port_deallocate(mach_task_self(), task);
return;
}
}

thread_array_t thread_list;
mach_msg_type_number_t thread_count;
ret = task_threads(task, &thread_list, &thread_count);
Expand Down
24 changes: 6 additions & 18 deletions darwin/DarwinProcessTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,6 @@ in the source distribution for its full text.
#include "zfs/ZfsArcStats.h"


static ProcessState ProcessTable_mapDarwinProcessState(int kinfo_proc_state) {
switch(kinfo_proc_state) {
case SRUN:
return RUNNING;
case SSLEEP:
return SLEEPING;
case SSTOP:
return STOPPED;
case SZOMB:
return ZOMBIE;
case SIDL:
return IDLE;
default:
return UNKNOWN;
}
}

static struct kinfo_proc* ProcessTable_getKInfoProcs(size_t* count) {
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 };
struct kinfo_proc* processes = NULL;
Expand Down Expand Up @@ -124,7 +107,12 @@ void ProcessTable_goThroughEntries(ProcessTable* super) {
proc->super.st_uid = ps[i].kp_eproc.e_ucred.cr_uid;
proc->super.user = UsersTable_getRef(host->usersTable, proc->super.st_uid);
}
proc->super.state = ProcessTable_mapDarwinProcessState(ps[i].kp_proc.p_stat);

if (ps[i].kp_proc.p_stat == SZOMB) {
proc->super.state = ZOMBIE;
} else if (ps[i].kp_proc.p_stat == SSTOP) {
proc->super.state = STOPPED;
}

// Disabled for High Sierra due to bug in macOS High Sierra
bool isScanThreadSupported = !Platform_KernelVersionIsBetween((KernelVersion) {17, 0, 0}, (KernelVersion) {17, 5, 0});
Expand Down

0 comments on commit 376afa9

Please sign in to comment.