From 7ca32041966453af2a8de125f50cdd6ec75688c4 Mon Sep 17 00:00:00 2001 From: aestriplex Date: Tue, 25 Feb 2025 11:14:49 +0100 Subject: [PATCH] darwin: Deduce the ZOMBIE and STOPPED state This uses kinfo_procs to deduce some further states, that were not covered in the libproc code. Co-authored-by: aestriplex Co-authored-by: Benny Baumann --- darwin/DarwinProcessTable.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/darwin/DarwinProcessTable.c b/darwin/DarwinProcessTable.c index 7fb0d4d69..9a2f6d5d0 100644 --- a/darwin/DarwinProcessTable.c +++ b/darwin/DarwinProcessTable.c @@ -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; @@ -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});