diff options
author | Wataru Ashihara <wsh@iij.ad.jp> | 2018-01-02 23:15:45 +0900 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-02-04 16:51:06 +0100 |
commit | b34d76cd41c8bbd7aa4ed92297b9e41eb0d52065 (patch) | |
tree | 73f3aa339b337ea6c7e58540800ddb831ea9422a | |
parent | 87be623eac49676ef0ac8e95733308dc12e37582 (diff) |
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`.
-rw-r--r-- | ProcessList.c | 5 |
1 files changed, 5 insertions, 0 deletions
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; |