From b34d76cd41c8bbd7aa4ed92297b9e41eb0d52065 Mon Sep 17 00:00:00 2001 From: Wataru Ashihara Date: Tue, 2 Jan 2018 23:15:45 +0900 Subject: Fix: infinite loop in tree view on macOS Fixes #688, the bug regressed on 584a9bc. On Mac OS X 10.11.6, all processes have their parents since there's a special process named "kernel_task", whose PID and PPID are 0. As a result, `this->processes` is never changed causing infinite `while`. --- ProcessList.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ProcessList.c b/ProcessList.c index 25ae1385..48b2d955 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -231,6 +231,11 @@ void ProcessList_sort(ProcessList* this) { pid_t ppid = process->tgid == process->pid ? process->ppid : process->tgid; // Bisect the process vector to find parent int l = 0, r = size; + // If PID corresponds with PPID (e.g. "kernel_task" (PID:0, PPID:0) + // on Mac OS X 10.11.6) cancel bisecting and regard this process as + // root. + if (process->pid == ppid) + r = 0; while (l < r) { int c = (l + r) / 2; pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid; -- cgit v1.2.3