Skip to content

Commit

Permalink
darwin: Deduce the ZOMBIE and STOPPED state
Browse files Browse the repository at this point in the history
This uses kinfo_procs to deduce some further states,
that were not covered in the libproc code.

Co-authored-by: aestriplex <[email protected]>
Co-authored-by: Benny Baumann <[email protected]>
  • Loading branch information
aestriplex and BenBE committed Feb 25, 2025
1 parent 3c825d3 commit 7ca3204
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 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 @@ -120,11 +103,17 @@ void ProcessTable_goThroughEntries(ProcessTable* super) {
DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting);
DarwinProcess_setFromLibprocPidinfo(proc, dpt, time_interval_ns);

// Deduce further process states not covered in the libproc call above
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;
}

if (proc->super.st_uid != ps[i].kp_eproc.e_ucred.cr_uid) {
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);

// 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 7ca3204

Please sign in to comment.